line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MARC::Charset::Code; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
896
|
use strict; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
799
|
|
4
|
18
|
|
|
18
|
|
102
|
use warnings; |
|
18
|
|
|
|
|
46
|
|
|
18
|
|
|
|
|
992
|
|
5
|
18
|
|
|
18
|
|
115
|
use base qw(Class::Accessor); |
|
18
|
|
|
|
|
37
|
|
|
18
|
|
|
|
|
37198
|
|
6
|
18
|
|
|
18
|
|
99455
|
use Carp qw(croak); |
|
18
|
|
|
|
|
49
|
|
|
18
|
|
|
|
|
1063
|
|
7
|
18
|
|
|
18
|
|
2378
|
use Encode qw(encode_utf8); |
|
18
|
|
|
|
|
28984
|
|
|
18
|
|
|
|
|
1195
|
|
8
|
18
|
|
|
18
|
|
9944
|
use MARC::Charset::Constants qw(:all); |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
25007
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
MARC::Charset::Code |
11
|
|
|
|
|
|
|
->mk_accessors(qw(marc ucs name charset is_combining alt |
12
|
|
|
|
|
|
|
marc_right_half marc_left_half)); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
MARC::Charset::Code - represents a MARC-8/UTF-8 mapping |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Each mapping from a MARC-8 value to a UTF-8 value is represented by |
23
|
|
|
|
|
|
|
a MARC::Charset::Code object in a MARC::Charset::Table. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 new() |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The constructor. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 name() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
A descriptive name for the code point. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 marc() |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
A string representing the MARC-8 bytes codes. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 ucs() |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
A string representing the UCS code point in hex. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 charset_code() |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
The MARC-8 character set code. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 is_combining() |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Returns true/false to tell if the character is a combining character. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 marc_left_half() |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
If the character is the right half of a "double diacritic", returns |
54
|
|
|
|
|
|
|
a hex string representing the MARC-8 value of the left half. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 marc_right_half() |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
If the character is the left half of a "double diacritic", returns |
59
|
|
|
|
|
|
|
a hex string representing the MARC-8 value of the right half. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 to_string() |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
A stringified version of the object suitable for pretty printing. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 char_value() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Returns the unicode character. Essentially just a helper around |
68
|
|
|
|
|
|
|
ucs(). |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub char_value |
73
|
|
|
|
|
|
|
{ |
74
|
361
|
|
|
361
|
1
|
859
|
return chr(hex(shift->ucs())); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 g0_marc_value() |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The string representing the MARC-8 encoding |
80
|
|
|
|
|
|
|
for lookup. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub g0_marc_value |
85
|
|
|
|
|
|
|
{ |
86
|
4
|
|
|
4
|
1
|
61
|
my $code = shift; |
87
|
4
|
|
|
|
|
13
|
my $marc = $code->marc(); |
88
|
4
|
100
|
|
|
|
49
|
if ($code->charset_name eq 'CJK') { |
89
|
|
|
|
|
|
|
return |
90
|
1
|
|
|
|
|
13
|
chr(hex(substr($marc,0,2))) . |
91
|
|
|
|
|
|
|
chr(hex(substr($marc,2,2))) . |
92
|
|
|
|
|
|
|
chr(hex(substr($marc,4,2))); |
93
|
|
|
|
|
|
|
} else { |
94
|
3
|
|
|
|
|
28
|
return chr(hex($marc)); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 marc_value() |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The string representing the MARC-8 encodingA |
101
|
|
|
|
|
|
|
for output. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub marc_value |
106
|
|
|
|
|
|
|
{ |
107
|
110
|
|
|
110
|
1
|
174
|
my $code = shift; |
108
|
110
|
|
|
|
|
540
|
my $marc = $code->marc(); |
109
|
110
|
100
|
|
|
|
1142
|
if ($code->charset_name eq 'CJK') { |
110
|
|
|
|
|
|
|
return |
111
|
1
|
|
|
|
|
12
|
chr(hex(substr($marc,0,2))) . |
112
|
|
|
|
|
|
|
chr(hex(substr($marc,2,2))) . |
113
|
|
|
|
|
|
|
chr(hex(substr($marc,4,2))); |
114
|
|
|
|
|
|
|
} else { |
115
|
109
|
100
|
|
|
|
286
|
if ($code->default_charset_group() eq 'G0') { |
116
|
87
|
|
|
|
|
766
|
return chr(hex($marc)); |
117
|
|
|
|
|
|
|
} else { |
118
|
22
|
|
|
|
|
133
|
return chr(hex($marc) + 128); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 charset_name() |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns the name of the character set, instead of the code. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub charset_name |
131
|
|
|
|
|
|
|
{ |
132
|
116
|
|
|
116
|
1
|
1390
|
return MARC::Charset::Constants::charset_name(shift->charset_value()); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 to_string() |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Returns a stringified version of the object. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub to_string |
142
|
|
|
|
|
|
|
{ |
143
|
8
|
|
|
8
|
1
|
141
|
my $self = shift; |
144
|
8
|
|
|
|
|
23
|
my $str = |
145
|
|
|
|
|
|
|
$self->name() . ': ' . |
146
|
|
|
|
|
|
|
'charset_code=' . $self->charset() . ' ' . |
147
|
|
|
|
|
|
|
'marc=' . $self->marc() . ' ' . |
148
|
|
|
|
|
|
|
'ucs=' . $self->ucs() . ' '; |
149
|
|
|
|
|
|
|
|
150
|
8
|
50
|
|
|
|
243
|
$str .= ' combining' if $self->is_combining(); |
151
|
8
|
|
|
|
|
94
|
return $str; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 marc8_hash_code() |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns a hash code for this Code object for looking up the object using |
158
|
|
|
|
|
|
|
MARC8. First portion is the character set code and the second is the |
159
|
|
|
|
|
|
|
MARC-8 value. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=cut |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub marc8_hash_code |
164
|
|
|
|
|
|
|
{ |
165
|
4
|
|
|
4
|
1
|
1570
|
my $self = shift; |
166
|
4
|
|
|
|
|
13
|
return sprintf('%s:%s', $self->charset_value(), $self->g0_marc_value()); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 utf8_hash_code() |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Returns a hash code for uniquely identifying a Code by it's UCS value. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub utf8_hash_code |
177
|
|
|
|
|
|
|
{ |
178
|
4
|
|
|
4
|
1
|
14
|
return int(hex(shift->ucs())); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 default_charset_group |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Returns 'G0' or 'G1' indicating where the character is typicalling used |
185
|
|
|
|
|
|
|
in the MARC-8 environment. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub default_charset_group |
190
|
|
|
|
|
|
|
{ |
191
|
208
|
|
|
208
|
1
|
850
|
my $charset = shift->charset_value(); |
192
|
|
|
|
|
|
|
|
193
|
208
|
100
|
33
|
|
|
6233
|
return 'G0' |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
194
|
|
|
|
|
|
|
if $charset eq ASCII_DEFAULT |
195
|
|
|
|
|
|
|
or $charset eq GREEK_SYMBOLS |
196
|
|
|
|
|
|
|
or $charset eq SUBSCRIPTS |
197
|
|
|
|
|
|
|
or $charset eq SUPERSCRIPTS |
198
|
|
|
|
|
|
|
or $charset eq BASIC_LATIN |
199
|
|
|
|
|
|
|
or $charset eq BASIC_ARABIC |
200
|
|
|
|
|
|
|
or $charset eq BASIC_CYRILLIC |
201
|
|
|
|
|
|
|
or $charset eq BASIC_GREEK |
202
|
|
|
|
|
|
|
or $charset eq BASIC_HEBREW |
203
|
|
|
|
|
|
|
or $charset eq CJK; |
204
|
|
|
|
|
|
|
|
205
|
32
|
|
|
|
|
156
|
return 'G1'; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 get_marc8_escape |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Returns an escape sequence to move to the Code from another marc-8 character |
212
|
|
|
|
|
|
|
set. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub get_escape |
217
|
|
|
|
|
|
|
{ |
218
|
13
|
|
|
13
|
0
|
35
|
my $charset = shift->charset_value(); |
219
|
|
|
|
|
|
|
|
220
|
13
|
100
|
33
|
|
|
258
|
return ESCAPE . $charset |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
221
|
|
|
|
|
|
|
if $charset eq ASCII_DEFAULT |
222
|
|
|
|
|
|
|
or $charset eq GREEK_SYMBOLS |
223
|
|
|
|
|
|
|
or $charset eq SUBSCRIPTS |
224
|
|
|
|
|
|
|
or $charset eq SUPERSCRIPTS; |
225
|
|
|
|
|
|
|
|
226
|
11
|
100
|
33
|
|
|
322
|
return ESCAPE . SINGLE_G0_A . $charset |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
227
|
|
|
|
|
|
|
if $charset eq ASCII_DEFAULT |
228
|
|
|
|
|
|
|
or $charset eq BASIC_LATIN |
229
|
|
|
|
|
|
|
or $charset eq BASIC_ARABIC |
230
|
|
|
|
|
|
|
or $charset eq BASIC_CYRILLIC |
231
|
|
|
|
|
|
|
or $charset eq BASIC_GREEK |
232
|
|
|
|
|
|
|
or $charset eq BASIC_HEBREW; |
233
|
|
|
|
|
|
|
|
234
|
3
|
100
|
66
|
|
|
31
|
return ESCAPE . SINGLE_G1_A . $charset |
|
|
|
100
|
|
|
|
|
235
|
|
|
|
|
|
|
if $charset eq EXTENDED_ARABIC |
236
|
|
|
|
|
|
|
or $charset eq EXTENDED_LATIN |
237
|
|
|
|
|
|
|
or $charset eq EXTENDED_CYRILLIC; |
238
|
|
|
|
|
|
|
|
239
|
1
|
50
|
|
|
|
7
|
return ESCAPE . MULTI_G0_A . CJK |
240
|
|
|
|
|
|
|
if $charset eq CJK; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 charset_value |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
Returns the charset value, not the hex sequence. |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub charset_value |
250
|
|
|
|
|
|
|
{ |
251
|
434
|
|
|
434
|
1
|
1132
|
return chr(hex(shift->charset())); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
1; |