File Coverage

blib/lib/ShiftJIS/Collate.pm
Criterion Covered Total %
statement 133 139 95.6
branch 98 124 79.0
condition 45 63 71.4
subroutine 22 24 91.6
pod 12 16 75.0
total 310 366 84.7


line stmt bran cond sub pod time code
1             package ShiftJIS::Collate;
2              
3 5     5   5297 use Carp;
  5         9  
  5         416  
4 5     5   24 use strict;
  5         8  
  5         162  
5 5     5   21 use vars qw($VERSION $PACKAGE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  5         10  
  5         45788  
6              
7             $VERSION = '1.10';
8              
9             $PACKAGE = 'ShiftJIS::Collate'; # __PACKAGE__
10              
11             my $Level = 4;
12             my $Kanji = 2;
13              
14             sub new {
15 105     105 0 7170 my $class = shift;
16 105         417 my $self = bless { @_ }, $class;
17              
18 105   66     359 $self->{level} ||= $Level;
19 105   66     351 $self->{kanji} ||= $Kanji;
20              
21 105 100       277 if ($self->{kanji} == 3) {
22 4 50 33     22 croak qq|$PACKAGE "tounicode" coderef is not defined|
23             unless $self->{tounicode} && ref($self->{tounicode}) eq 'CODE';
24             }
25 105 100       226 if (exists $self->{overrideCJK}) {
26 1         209 croak qq|$PACKAGE : Sorry, "overrideCJK" is obsolete.|;
27             }
28 104         375 return $self;
29             }
30              
31              
32             my $Char = '[\xB3\xB6-\xC4]\xDE|[\xCA-\xCE][\xDE\xDF]|'
33             . '[\x00-\x7F\xA1-\xDF]|[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]';
34              
35             my $CJK = '\x88[\x9F-\xFC]|\x98[\x40-\x72\x9F-\xFC]|'
36             . '[\x89-\x97\x99-\x9F\xE0-\xE9][\x40-\x7E\x80-\xFC]|'
37             . '\xEA[\x40-\x7E\x80-\xA4]';
38              
39              
40             #
41             # 1st weights
42             #
43             # /[\x41-\xFF]{2}/
44             #
45             # 2nd weights
46             # "\x32" : unaffected
47             # "\x33" : normal latin
48             # "\x34" : voiceless kana
49             # "\x35" : voiced kana
50             # "\x36" : semivoiced kana
51             #
52             # 3rd weights
53             # "\x14" : unaffected
54             # "\x15" : lower latin
55             # "\x16" : upper latin
56             # "\x1a" : prolonged kana
57             # "\x1b" : small kana
58             # "\x1c" : iteration kana
59             # "\x1d" : normal kana
60             #
61             # 4th weights
62             # "\x0a" : unaffected
63             # "\x10" : hiragana
64             # "\x11" : katakana
65             #
66             # 5th weights
67             # "\x01" : unaffected
68             # "\x02" : normal ascii
69             # "\x03" : normal kana
70             # "\x04" : compat kana
71             # "\x05" : compat ascii
72             #
73             my %Order = (
74              
75             ' ' => "\x70\x41\x32\x14\x0a\x01",
76             '@' => "\x70\x42\x32\x14\x0a\x01",
77             'A' => "\x71\x41\x32\x14\x0a\x03",
78             '' => "\x71\x41\x32\x14\x0a\x04",
79             'B' => "\x71\x42\x32\x14\x0a\x03",
80             '' => "\x71\x42\x32\x14\x0a\x04",
81             ',' => "\x71\x43\x32\x14\x0a\x02",
82             'C' => "\x71\x43\x32\x14\x0a\x05",
83             '.' => "\x71\x44\x32\x14\x0a\x02",
84             'D' => "\x71\x44\x32\x14\x0a\x05",
85             'E' => "\x71\x45\x32\x14\x0a\x03",
86             '' => "\x71\x45\x32\x14\x0a\x04",
87             ':' => "\x71\x46\x32\x14\x0a\x02",
88             'F' => "\x71\x46\x32\x14\x0a\x05",
89             ';' => "\x71\x47\x32\x14\x0a\x02",
90             'G' => "\x71\x47\x32\x14\x0a\x05",
91             '?' => "\x71\x48\x32\x14\x0a\x02",
92             'H' => "\x71\x48\x32\x14\x0a\x05",
93             '!' => "\x71\x49\x32\x14\x0a\x02",
94             'I' => "\x71\x49\x32\x14\x0a\x05",
95             'L' => "\x71\x4a\x32\x14\x0a\x01",#added
96             '`' => "\x71\x4b\x32\x14\x0a\x02",#added
97             'M' => "\x71\x4b\x32\x14\x0a\x05",#added
98             'N' => "\x71\x4c\x32\x14\x0a\x01",#added
99             '^' => "\x71\x4d\x32\x14\x0a\x02",#added
100             'O' => "\x71\x4d\x32\x14\x0a\x05",#added
101             '~' => "\x71\x4e\x32\x14\x0a\x02",
102             'P' => "\x71\x4e\x32\x14\x0a\x05",
103             '_' => "\x71\x4f\x32\x14\x0a\x02",
104             'Q' => "\x71\x4f\x32\x14\x0a\x05",
105             (qw/\ /)[0]
106             => "\x71\x50\x32\x14\x0a\x01",
107             ']' => "\x71\x51\x32\x14\x0a\x01",
108             '/' => "\x71\x52\x32\x14\x0a\x02",
109             '^' => "\x71\x52\x32\x14\x0a\x05",
110             '_' => "\x71\x53\x32\x14\x0a\x01",
111             '`' => "\x71\x54\x32\x14\x0a\x01",
112             'a' => "\x71\x55\x32\x14\x0a\x01",
113             '|' => "\x71\x56\x32\x14\x0a\x02",
114             'b' => "\x71\x56\x32\x14\x0a\x05",
115             'c' => "\x71\x57\x32\x14\x0a\x01",
116             'd' => "\x71\x58\x32\x14\x0a\x01",
117             q|e|=> "\x72\x41\x32\x14\x0a\x01",
118             q|f|=> "\x72\x42\x32\x14\x0a\x01",
119             q|'| => "\x72\x43\x32\x14\x0a\x01",#added
120             q|g|=> "\x72\x44\x32\x14\x0a\x01",
121             q|h|=> "\x72\x45\x32\x14\x0a\x01",
122             q|"| => "\x72\x46\x32\x14\x0a\x01",#added
123             '(' => "\x72\x47\x32\x14\x0a\x02",
124             'i' => "\x72\x47\x32\x14\x0a\x05",
125             ')' => "\x72\x48\x32\x14\x0a\x02",
126             'j' => "\x72\x48\x32\x14\x0a\x05",
127             'k' => "\x72\x49\x32\x14\x0a\x01",
128             'l' => "\x72\x4a\x32\x14\x0a\x01",
129             '[' => "\x72\x4b\x32\x14\x0a\x02",
130             'm' => "\x72\x4b\x32\x14\x0a\x05",
131             ']' => "\x72\x4c\x32\x14\x0a\x02",
132             'n' => "\x72\x4c\x32\x14\x0a\x05",
133             '{' => "\x72\x4d\x32\x14\x0a\x02",
134             'o' => "\x72\x4d\x32\x14\x0a\x05",
135             '}' => "\x72\x4e\x32\x14\x0a\x02",
136             'p' => "\x72\x4e\x32\x14\x0a\x05",
137             'q' => "\x72\x4f\x32\x14\x0a\x01",
138             'r' => "\x72\x50\x32\x14\x0a\x01",
139             's' => "\x72\x51\x32\x14\x0a\x01",
140             't' => "\x72\x52\x32\x14\x0a\x01",
141             'u' => "\x72\x53\x32\x14\x0a\x03",
142             '' => "\x72\x53\x32\x14\x0a\x04",
143             'v' => "\x72\x54\x32\x14\x0a\x03",
144             '' => "\x72\x54\x32\x14\x0a\x04",
145             'w' => "\x72\x55\x32\x14\x0a\x01",
146             'x' => "\x72\x56\x32\x14\x0a\x01",
147             'y' => "\x72\x57\x32\x14\x0a\x01",
148             'z' => "\x72\x58\x32\x14\x0a\x01",
149             '+' => "\x73\x41\x32\x14\x0a\x02",
150             '{' => "\x73\x41\x32\x14\x0a\x05",
151             '-' => "\x73\x42\x32\x14\x0a\x01",#added
152             '|' => "\x73\x43\x32\x14\x0a\x01",
153             '}' => "\x73\x44\x32\x14\x0a\x01",
154             '~' => "\x73\x45\x32\x14\x0a\x01",
155             '' => "\x73\x46\x32\x14\x0a\x01",
156             '=' => "\x73\x47\x32\x14\x0a\x02",
157             '' => "\x73\x47\x32\x14\x0a\x05",
158             '' => "\x73\x48\x32\x14\x0a\x01",
159             '<' => "\x73\x49\x32\x14\x0a\x02",
160             '' => "\x73\x49\x32\x14\x0a\x05",
161             '>' => "\x73\x4a\x32\x14\x0a\x02",
162             '' => "\x73\x4a\x32\x14\x0a\x05",
163             '' => "\x73\x4b\x32\x14\x0a\x01",
164             '' => "\x73\x4c\x32\x14\x0a\x01",
165             '' => "\x73\x4d\x32\x14\x0a\x01",
166             '' => "\x73\x4e\x32\x14\x0a\x01",
167             '' => "\x73\x4f\x32\x14\x0a\x01",
168             '' => "\x73\x50\x32\x14\x0a\x01",
169             '' => "\x73\x51\x32\x14\x0a\x01",
170             '' => "\x73\x52\x32\x14\x0a\x01",
171             '' => "\x73\x53\x32\x14\x0a\x01",
172             '' => "\x73\x54\x32\x14\x0a\x01",
173             '' => "\x73\x55\x32\x14\x0a\x01",
174             '' => "\x73\x56\x32\x14\x0a\x01",
175             '' => "\x73\x57\x32\x14\x0a\x01",
176             '' => "\x73\x58\x32\x14\x0a\x01",
177             '' => "\x73\x59\x32\x14\x0a\x01",
178             '' => "\x73\x5a\x32\x14\x0a\x01",
179             '' => "\x73\x5b\x32\x14\x0a\x01",
180             '' => "\x73\x5c\x32\x14\x0a\x01",
181             '' => "\x73\x5d\x32\x14\x0a\x01",
182             '' => "\x73\x5e\x32\x14\x0a\x01",
183             '' => "\x73\x5f\x32\x14\x0a\x01",
184             '' => "\x73\x60\x32\x14\x0a\x01",
185             '' => "\x73\x61\x32\x14\x0a\x01",
186             '' => "\x73\x62\x32\x14\x0a\x01",
187             '' => "\x73\x63\x32\x14\x0a\x01",
188             '' => "\x73\x64\x32\x14\x0a\x01",
189             '' => "\x73\x65\x32\x14\x0a\x01",
190             '' => "\x73\x66\x32\x14\x0a\x01",
191             '' => "\x73\x67\x32\x14\x0a\x01",
192             '' => "\x73\x68\x32\x14\x0a\x01",
193             '' => "\x73\x69\x32\x14\x0a\x01",
194             '' => "\x73\x6a\x32\x14\x0a\x01",
195             '' => "\x73\x6b\x32\x14\x0a\x01",
196             '' => "\x73\x6c\x32\x14\x0a\x01",
197             '' => "\x73\x6d\x32\x14\x0a\x01",
198             '' => "\x73\x6e\x32\x14\x0a\x01",
199             '#' => "\x74\x41\x32\x14\x0a\x02",
200             '' => "\x74\x41\x32\x14\x0a\x05",
201             '&' => "\x74\x42\x32\x14\x0a\x02",
202             '' => "\x74\x42\x32\x14\x0a\x05",
203             '*' => "\x74\x43\x32\x14\x0a\x02",
204             '' => "\x74\x43\x32\x14\x0a\x05",
205             '@' => "\x74\x44\x32\x14\x0a\x02",
206             '' => "\x74\x44\x32\x14\x0a\x05",
207             '' => "\x74\x45\x32\x14\x0a\x01",
208             '' => "\x74\x46\x32\x14\x0a\x01",
209             '' => "\x74\x47\x32\x14\x0a\x01",
210             '' => "\x74\x48\x32\x14\x0a\x01",
211             '' => "\x74\x49\x32\x14\x0a\x01",
212             '' => "\x74\x4a\x32\x14\x0a\x01",
213             '' => "\x74\x4b\x32\x14\x0a\x01",
214             '' => "\x74\x4c\x32\x14\x0a\x01",
215             '' => "\x74\x4d\x32\x14\x0a\x01",
216             '' => "\x74\x4e\x32\x14\x0a\x01",
217             '' => "\x74\x4f\x32\x14\x0a\x01",
218             '' => "\x74\x50\x32\x14\x0a\x01",
219             '' => "\x74\x51\x32\x14\x0a\x01",
220             '' => "\x74\x52\x32\x14\x0a\x01",
221             '' => "\x74\x53\x32\x14\x0a\x01",
222             '' => "\x74\x54\x32\x14\x0a\x01",
223             '' => "\x74\x55\x32\x14\x0a\x01",
224             '' => "\x74\x56\x32\x14\x0a\x01",
225             '' => "\x74\x57\x32\x14\x0a\x01",
226             '' => "\x74\x58\x32\x14\x0a\x01",
227             '' => "\x74\x59\x32\x14\x0a\x01",
228             '' => "\x74\x5a\x32\x14\x0a\x01",
229             '' => "\x74\x5b\x32\x14\x0a\x01",
230             '' => "\x74\x5c\x32\x14\x0a\x01",
231             '' => "\x74\x5d\x32\x14\x0a\x01",
232             '' => "\x74\x5e\x32\x14\x0a\x01",
233             '' => "\x75\x41\x32\x14\x0a\x01",
234             '' => "\x75\x42\x32\x14\x0a\x01",
235             '' => "\x75\x43\x32\x14\x0a\x01",
236             '' => "\x75\x44\x32\x14\x0a\x01",
237             '\\' => "\x75\x45\x32\x14\x0a\x02",
238             '' => "\x75\x45\x32\x14\x0a\x05",
239             '$' => "\x75\x46\x32\x14\x0a\x02",
240             '' => "\x75\x46\x32\x14\x0a\x05",
241             '' => "\x75\x47\x32\x14\x0a\x01",
242             '' => "\x75\x48\x32\x14\x0a\x01",
243             '%' => "\x75\x49\x32\x14\x0a\x02",
244             '' => "\x75\x49\x32\x14\x0a\x05",
245             '' => "\x75\x4a\x32\x14\x0a\x01",
246             '' => "\x75\x4b\x32\x14\x0a\x01",
247             '0' => "\x76\x41\x32\x14\x0a\x02",
248             'O' => "\x76\x41\x32\x14\x0a\x05",
249             '1' => "\x76\x42\x32\x14\x0a\x02",
250             'P' => "\x76\x42\x32\x14\x0a\x05",
251             '2' => "\x76\x43\x32\x14\x0a\x02",
252             'Q' => "\x76\x43\x32\x14\x0a\x05",
253             '3' => "\x76\x44\x32\x14\x0a\x02",
254             'R' => "\x76\x44\x32\x14\x0a\x05",
255             '4' => "\x76\x45\x32\x14\x0a\x02",
256             'S' => "\x76\x45\x32\x14\x0a\x05",
257             '5' => "\x76\x46\x32\x14\x0a\x02",
258             'T' => "\x76\x46\x32\x14\x0a\x05",
259             '6' => "\x76\x47\x32\x14\x0a\x02",
260             'U' => "\x76\x47\x32\x14\x0a\x05",
261             '7' => "\x76\x48\x32\x14\x0a\x02",
262             'V' => "\x76\x48\x32\x14\x0a\x05",
263             '8' => "\x76\x49\x32\x14\x0a\x02",
264             'W' => "\x76\x49\x32\x14\x0a\x05",
265             '9' => "\x76\x4a\x32\x14\x0a\x02",
266             'X' => "\x76\x4a\x32\x14\x0a\x05",
267             '' => "\x77\x41\x32\x14\x0a\x01",
268             '' => "\x77\x42\x32\x14\x0a\x01",
269             '' => "\x77\x43\x32\x14\x0a\x01",
270             '' => "\x77\x44\x32\x14\x0a\x01",
271             '' => "\x77\x45\x32\x14\x0a\x01",
272             '' => "\x77\x46\x32\x14\x0a\x01",
273             '' => "\x77\x47\x32\x14\x0a\x01",
274             '' => "\x77\x48\x32\x14\x0a\x01",
275             '' => "\x77\x49\x32\x14\x0a\x01",
276             '' => "\x77\x4a\x32\x14\x0a\x01",
277             '' => "\x77\x4b\x32\x14\x0a\x01",
278             '' => "\x77\x4c\x32\x14\x0a\x01",
279             '' => "\x77\x4d\x32\x14\x0a\x01",
280             '' => "\x77\x4e\x32\x14\x0a\x01",
281             '' => "\x77\x4f\x32\x14\x0a\x01",
282             '' => "\x77\x50\x32\x14\x0a\x01",
283             '' => "\x77\x51\x32\x14\x0a\x01",
284             '' => "\x77\x52\x32\x14\x0a\x01",
285             '' => "\x77\x53\x32\x14\x0a\x01",
286             '' => "\x77\x54\x32\x14\x0a\x01",
287             '' => "\x77\x55\x32\x14\x0a\x01",
288             '' => "\x77\x56\x32\x14\x0a\x01",
289             '' => "\x77\x57\x32\x14\x0a\x01",
290             '' => "\x77\x58\x32\x14\x0a\x01",
291             '' => "\x77\x61\x32\x14\x0a\x01",
292             '' => "\x77\x62\x32\x14\x0a\x01",
293             '' => "\x77\x63\x32\x14\x0a\x01",
294             '' => "\x77\x64\x32\x14\x0a\x01",
295             '' => "\x77\x65\x32\x14\x0a\x01",
296             '' => "\x77\x66\x32\x14\x0a\x01",
297             '' => "\x77\x67\x32\x14\x0a\x01",
298             '' => "\x77\x68\x32\x14\x0a\x01",
299             '' => "\x77\x69\x32\x14\x0a\x01",
300             '' => "\x77\x6a\x32\x14\x0a\x01",
301             '' => "\x77\x6b\x32\x14\x0a\x01",
302             '' => "\x77\x6c\x32\x14\x0a\x01",
303             '' => "\x77\x6d\x32\x14\x0a\x01",
304             '' => "\x77\x6e\x32\x14\x0a\x01",
305             '' => "\x77\x6f\x32\x14\x0a\x01",
306             '' => "\x77\x70\x32\x14\x0a\x01",
307             '' => "\x77\x71\x32\x14\x0a\x01",
308             '' => "\x77\x72\x32\x14\x0a\x01",
309             '' => "\x77\x73\x32\x14\x0a\x01",
310             '' => "\x77\x74\x32\x14\x0a\x01",
311             '' => "\x77\x75\x32\x14\x0a\x01",
312             '' => "\x77\x76\x32\x14\x0a\x01",
313             '' => "\x77\x77\x32\x14\x0a\x01",
314             '' => "\x77\x78\x32\x14\x0a\x01",
315             'p' => "\x77\x81\x32\x14\x0a\x01",
316             'q' => "\x77\x82\x32\x14\x0a\x01",
317             'r' => "\x77\x83\x32\x14\x0a\x01",
318             's' => "\x77\x84\x32\x14\x0a\x01",
319             't' => "\x77\x85\x32\x14\x0a\x01",
320             'u' => "\x77\x86\x32\x14\x0a\x01",
321             'v' => "\x77\x87\x32\x14\x0a\x01",
322             'w' => "\x77\x88\x32\x14\x0a\x01",
323             'x' => "\x77\x89\x32\x14\x0a\x01",
324             'y' => "\x77\x8a\x32\x14\x0a\x01",
325             'z' => "\x77\x8b\x32\x14\x0a\x01",
326             '{' => "\x77\x8c\x32\x14\x0a\x01",
327             '|' => "\x77\x8d\x32\x14\x0a\x01",
328             '}' => "\x77\x8e\x32\x14\x0a\x01",
329             '~' => "\x77\x8f\x32\x14\x0a\x01",
330             '' => "\x77\x90\x32\x14\x0a\x01",
331             '' => "\x77\x91\x32\x14\x0a\x01",
332             '' => "\x77\x92\x32\x14\x0a\x01",
333             '' => "\x77\x93\x32\x14\x0a\x01",
334             '' => "\x77\x94\x32\x14\x0a\x01",
335             '' => "\x77\x95\x32\x14\x0a\x01",
336             '' => "\x77\x96\x32\x14\x0a\x01",
337             '' => "\x77\x97\x32\x14\x0a\x01",
338             '' => "\x77\x98\x32\x14\x0a\x01",
339             '' => "\x77\x99\x32\x14\x0a\x01",
340             '' => "\x77\x9a\x32\x14\x0a\x01",
341             '' => "\x77\x9b\x32\x14\x0a\x01",
342             '' => "\x77\x9c\x32\x14\x0a\x01",
343             '' => "\x77\x9d\x32\x14\x0a\x01",
344             '' => "\x77\x9e\x32\x14\x0a\x01",
345             '' => "\x77\x9f\x32\x14\x0a\x01",
346             '' => "\x77\xa0\x32\x14\x0a\x01",
347             '' => "\x77\xa1\x32\x14\x0a\x01",
348             '@' => "\x77\xb1\x32\x14\x0a\x01",
349             'A' => "\x77\xb2\x32\x14\x0a\x01",
350             'B' => "\x77\xb3\x32\x14\x0a\x01",
351             'C' => "\x77\xb4\x32\x14\x0a\x01",
352             'D' => "\x77\xb5\x32\x14\x0a\x01",
353             'E' => "\x77\xb6\x32\x14\x0a\x01",
354             'F' => "\x77\xb7\x32\x14\x0a\x01",
355             'G' => "\x77\xb8\x32\x14\x0a\x01",
356             'H' => "\x77\xb9\x32\x14\x0a\x01",
357             'I' => "\x77\xba\x32\x14\x0a\x01",
358             'J' => "\x77\xbb\x32\x14\x0a\x01",
359             'K' => "\x77\xbc\x32\x14\x0a\x01",
360             'L' => "\x77\xbd\x32\x14\x0a\x01",
361             'M' => "\x77\xbe\x32\x14\x0a\x01",
362             'N' => "\x77\xbf\x32\x14\x0a\x01",
363             'O' => "\x77\xc0\x32\x14\x0a\x01",
364             'P' => "\x77\xc1\x32\x14\x0a\x01",
365             'Q' => "\x77\xc2\x32\x14\x0a\x01",
366             'R' => "\x77\xc3\x32\x14\x0a\x01",
367             'S' => "\x77\xc4\x32\x14\x0a\x01",
368             'T' => "\x77\xc5\x32\x14\x0a\x01",
369             'U' => "\x77\xc6\x32\x14\x0a\x01",
370             'V' => "\x77\xc7\x32\x14\x0a\x01",
371             'W' => "\x77\xc8\x32\x14\x0a\x01",
372             'X' => "\x77\xc9\x32\x14\x0a\x01",
373             'Y' => "\x77\xca\x32\x14\x0a\x01",
374             'Z' => "\x77\xcb\x32\x14\x0a\x01",
375             '[' => "\x77\xcc\x32\x14\x0a\x01",
376             (qw/\ /)[0]
377             => "\x77\xcd\x32\x14\x0a\x01",
378             ']' => "\x77\xce\x32\x14\x0a\x01",
379             '^' => "\x77\xcf\x32\x14\x0a\x01",
380             '_' => "\x77\xd0\x32\x14\x0a\x01",
381             '`' => "\x77\xd1\x32\x14\x0a\x01",
382             'a' => "\x78\x41\x33\x15\x0a\x02",
383             '' => "\x78\x41\x33\x15\x0a\x05",
384             'A' => "\x78\x41\x33\x16\x0a\x02",
385             '`' => "\x78\x41\x33\x16\x0a\x05",
386             'b' => "\x78\x42\x33\x15\x0a\x02",
387             '' => "\x78\x42\x33\x15\x0a\x05",
388             'B' => "\x78\x42\x33\x16\x0a\x02",
389             'a' => "\x78\x42\x33\x16\x0a\x05",
390             'c' => "\x78\x43\x33\x15\x0a\x02",
391             '' => "\x78\x43\x33\x15\x0a\x05",
392             'C' => "\x78\x43\x33\x16\x0a\x02",
393             'b' => "\x78\x43\x33\x16\x0a\x05",
394             'd' => "\x78\x44\x33\x15\x0a\x02",
395             '' => "\x78\x44\x33\x15\x0a\x05",
396             'D' => "\x78\x44\x33\x16\x0a\x02",
397             'c' => "\x78\x44\x33\x16\x0a\x05",
398             'e' => "\x78\x45\x33\x15\x0a\x02",
399             '' => "\x78\x45\x33\x15\x0a\x05",
400             'E' => "\x78\x45\x33\x16\x0a\x02",
401             'd' => "\x78\x45\x33\x16\x0a\x05",
402             'f' => "\x78\x46\x33\x15\x0a\x02",
403             '' => "\x78\x46\x33\x15\x0a\x05",
404             'F' => "\x78\x46\x33\x16\x0a\x02",
405             'e' => "\x78\x46\x33\x16\x0a\x05",
406             'g' => "\x78\x47\x33\x15\x0a\x02",
407             '' => "\x78\x47\x33\x15\x0a\x05",
408             'G' => "\x78\x47\x33\x16\x0a\x02",
409             'f' => "\x78\x47\x33\x16\x0a\x05",
410             'h' => "\x78\x48\x33\x15\x0a\x02",
411             '' => "\x78\x48\x33\x15\x0a\x05",
412             'H' => "\x78\x48\x33\x16\x0a\x02",
413             'g' => "\x78\x48\x33\x16\x0a\x05",
414             'i' => "\x78\x49\x33\x15\x0a\x02",
415             '' => "\x78\x49\x33\x15\x0a\x05",
416             'I' => "\x78\x49\x33\x16\x0a\x02",
417             'h' => "\x78\x49\x33\x16\x0a\x05",
418             'j' => "\x78\x4a\x33\x15\x0a\x02",
419             '' => "\x78\x4a\x33\x15\x0a\x05",
420             'J' => "\x78\x4a\x33\x16\x0a\x02",
421             'i' => "\x78\x4a\x33\x16\x0a\x05",
422             'k' => "\x78\x4b\x33\x15\x0a\x02",
423             '' => "\x78\x4b\x33\x15\x0a\x05",
424             'K' => "\x78\x4b\x33\x16\x0a\x02",
425             'j' => "\x78\x4b\x33\x16\x0a\x05",
426             'l' => "\x78\x4c\x33\x15\x0a\x02",
427             '' => "\x78\x4c\x33\x15\x0a\x05",
428             'L' => "\x78\x4c\x33\x16\x0a\x02",
429             'k' => "\x78\x4c\x33\x16\x0a\x05",
430             'm' => "\x78\x4d\x33\x15\x0a\x02",
431             '' => "\x78\x4d\x33\x15\x0a\x05",
432             'M' => "\x78\x4d\x33\x16\x0a\x02",
433             'l' => "\x78\x4d\x33\x16\x0a\x05",
434             'n' => "\x78\x4e\x33\x15\x0a\x02",
435             '' => "\x78\x4e\x33\x15\x0a\x05",
436             'N' => "\x78\x4e\x33\x16\x0a\x02",
437             'm' => "\x78\x4e\x33\x16\x0a\x05",
438             'o' => "\x78\x4f\x33\x15\x0a\x02",
439             '' => "\x78\x4f\x33\x15\x0a\x05",
440             'O' => "\x78\x4f\x33\x16\x0a\x02",
441             'n' => "\x78\x4f\x33\x16\x0a\x05",
442             'p' => "\x78\x50\x33\x15\x0a\x02",
443             '' => "\x78\x50\x33\x15\x0a\x05",
444             'P' => "\x78\x50\x33\x16\x0a\x02",
445             'o' => "\x78\x50\x33\x16\x0a\x05",
446             'q' => "\x78\x51\x33\x15\x0a\x02",
447             '' => "\x78\x51\x33\x15\x0a\x05",
448             'Q' => "\x78\x51\x33\x16\x0a\x02",
449             'p' => "\x78\x51\x33\x16\x0a\x05",
450             'r' => "\x78\x52\x33\x15\x0a\x02",
451             '' => "\x78\x52\x33\x15\x0a\x05",
452             'R' => "\x78\x52\x33\x16\x0a\x02",
453             'q' => "\x78\x52\x33\x16\x0a\x05",
454             's' => "\x78\x53\x33\x15\x0a\x02",
455             '' => "\x78\x53\x33\x15\x0a\x05",
456             'S' => "\x78\x53\x33\x16\x0a\x02",
457             'r' => "\x78\x53\x33\x16\x0a\x05",
458             't' => "\x78\x54\x33\x15\x0a\x02",
459             '' => "\x78\x54\x33\x15\x0a\x05",
460             'T' => "\x78\x54\x33\x16\x0a\x02",
461             's' => "\x78\x54\x33\x16\x0a\x05",
462             'u' => "\x78\x55\x33\x15\x0a\x02",
463             '' => "\x78\x55\x33\x15\x0a\x05",
464             'U' => "\x78\x55\x33\x16\x0a\x02",
465             't' => "\x78\x55\x33\x16\x0a\x05",
466             'v' => "\x78\x56\x33\x15\x0a\x02",
467             '' => "\x78\x56\x33\x15\x0a\x05",
468             'V' => "\x78\x56\x33\x16\x0a\x02",
469             'u' => "\x78\x56\x33\x16\x0a\x05",
470             'w' => "\x78\x57\x33\x15\x0a\x02",
471             '' => "\x78\x57\x33\x15\x0a\x05",
472             'W' => "\x78\x57\x33\x16\x0a\x02",
473             'v' => "\x78\x57\x33\x16\x0a\x05",
474             'x' => "\x78\x58\x33\x15\x0a\x02",
475             '' => "\x78\x58\x33\x15\x0a\x05",
476             'X' => "\x78\x58\x33\x16\x0a\x02",
477             'w' => "\x78\x58\x33\x16\x0a\x05",
478             'y' => "\x78\x59\x33\x15\x0a\x02",
479             '' => "\x78\x59\x33\x15\x0a\x05",
480             'Y' => "\x78\x59\x33\x16\x0a\x02",
481             'x' => "\x78\x59\x33\x16\x0a\x05",
482             'z' => "\x78\x5a\x33\x15\x0a\x02",
483             '' => "\x78\x5a\x33\x15\x0a\x05",
484             'Z' => "\x78\x5a\x33\x16\x0a\x02",
485             'y' => "\x78\x5a\x33\x16\x0a\x05",
486             '' => "\x79\x41\x34\x1b\x10\x03",
487             '@' => "\x79\x41\x34\x1b\x11\x03",
488             '' => "\x79\x41\x34\x1b\x11\x04",
489             '' => "\x79\x41\x34\x1d\x10\x03",
490             'A' => "\x79\x41\x34\x1d\x11\x03",
491             '' => "\x79\x41\x34\x1d\x11\x04",
492             '' => "\x79\x42\x34\x1b\x10\x03",
493             'B' => "\x79\x42\x34\x1b\x11\x03",
494             '' => "\x79\x42\x34\x1b\x11\x04",
495             '' => "\x79\x42\x34\x1d\x10\x03",
496             'C' => "\x79\x42\x34\x1d\x11\x03",
497             '' => "\x79\x42\x34\x1d\x11\x04",
498             '' => "\x79\x43\x34\x1b\x10\x03",
499             'D' => "\x79\x43\x34\x1b\x11\x03",
500             '' => "\x79\x43\x34\x1b\x11\x04",
501             '' => "\x79\x43\x34\x1d\x10\x03",
502             'E' => "\x79\x43\x34\x1d\x11\x03",
503             '' => "\x79\x43\x34\x1d\x11\x04",
504             '' => "\x79\x43\x35\x1d\x11\x03",
505             '' => "\x79\x43\x35\x1d\x11\x04",
506             '' => "\x79\x44\x34\x1b\x10\x03",
507             'F' => "\x79\x44\x34\x1b\x11\x03",
508             '' => "\x79\x44\x34\x1b\x11\x04",
509             '' => "\x79\x44\x34\x1d\x10\x03",
510             'G' => "\x79\x44\x34\x1d\x11\x03",
511             '' => "\x79\x44\x34\x1d\x11\x04",
512             '' => "\x79\x45\x34\x1b\x10\x03",
513             'H' => "\x79\x45\x34\x1b\x11\x03",
514             '' => "\x79\x45\x34\x1b\x11\x04",
515             '' => "\x79\x45\x34\x1d\x10\x03",
516             'I' => "\x79\x45\x34\x1d\x11\x03",
517             '' => "\x79\x45\x34\x1d\x11\x04",
518             '' => "\x79\x51\x34\x1b\x11\x03",
519             '' => "\x79\x51\x34\x1d\x10\x03",
520             'J' => "\x79\x51\x34\x1d\x11\x03",
521             '' => "\x79\x51\x34\x1d\x11\x04",
522             '' => "\x79\x51\x35\x1d\x10\x03",
523             'K' => "\x79\x51\x35\x1d\x11\x03",
524             '' => "\x79\x51\x35\x1d\x11\x04",
525             '' => "\x79\x52\x34\x1d\x10\x03",
526             'L' => "\x79\x52\x34\x1d\x11\x03",
527             '' => "\x79\x52\x34\x1d\x11\x04",
528             '' => "\x79\x52\x35\x1d\x10\x03",
529             'M' => "\x79\x52\x35\x1d\x11\x03",
530             '' => "\x79\x52\x35\x1d\x11\x04",
531             '' => "\x79\x53\x34\x1d\x10\x03",
532             'N' => "\x79\x53\x34\x1d\x11\x03",
533             '' => "\x79\x53\x34\x1d\x11\x04",
534             '' => "\x79\x53\x35\x1d\x10\x03",
535             'O' => "\x79\x53\x35\x1d\x11\x03",
536             '' => "\x79\x53\x35\x1d\x11\x04",
537             '' => "\x79\x54\x34\x1b\x11\x03",
538             '' => "\x79\x54\x34\x1d\x10\x03",
539             'P' => "\x79\x54\x34\x1d\x11\x03",
540             '' => "\x79\x54\x34\x1d\x11\x04",
541             '' => "\x79\x54\x35\x1d\x10\x03",
542             'Q' => "\x79\x54\x35\x1d\x11\x03",
543             '' => "\x79\x54\x35\x1d\x11\x04",
544             '' => "\x79\x55\x34\x1d\x10\x03",
545             'R' => "\x79\x55\x34\x1d\x11\x03",
546             '' => "\x79\x55\x34\x1d\x11\x04",
547             '' => "\x79\x55\x35\x1d\x10\x03",
548             'S' => "\x79\x55\x35\x1d\x11\x03",
549             '' => "\x79\x55\x35\x1d\x11\x04",
550             '' => "\x79\x61\x34\x1d\x10\x03",
551             'T' => "\x79\x61\x34\x1d\x11\x03",
552             '' => "\x79\x61\x34\x1d\x11\x04",
553             '' => "\x79\x61\x35\x1d\x10\x03",
554             'U' => "\x79\x61\x35\x1d\x11\x03",
555             '' => "\x79\x61\x35\x1d\x11\x04",
556             '' => "\x79\x62\x34\x1d\x10\x03",
557             'V' => "\x79\x62\x34\x1d\x11\x03",
558             '' => "\x79\x62\x34\x1d\x11\x04",
559             '' => "\x79\x62\x35\x1d\x10\x03",
560             'W' => "\x79\x62\x35\x1d\x11\x03",
561             '' => "\x79\x62\x35\x1d\x11\x04",
562             '' => "\x79\x63\x34\x1d\x10\x03",
563             'X' => "\x79\x63\x34\x1d\x11\x03",
564             '' => "\x79\x63\x34\x1d\x11\x04",
565             '' => "\x79\x63\x35\x1d\x10\x03",
566             'Y' => "\x79\x63\x35\x1d\x11\x03",
567             '' => "\x79\x63\x35\x1d\x11\x04",
568             '' => "\x79\x64\x34\x1d\x10\x03",
569             'Z' => "\x79\x64\x34\x1d\x11\x03",
570             '' => "\x79\x64\x34\x1d\x11\x04",
571             '' => "\x79\x64\x35\x1d\x10\x03",
572             '[' => "\x79\x64\x35\x1d\x11\x03",
573             '' => "\x79\x64\x35\x1d\x11\x04",
574             '' => "\x79\x65\x34\x1d\x10\x03",
575             (qw/\ /)[0]
576             => "\x79\x65\x34\x1d\x11\x03",
577             '' => "\x79\x65\x34\x1d\x11\x04",
578             '' => "\x79\x65\x35\x1d\x10\x03",
579             ']' => "\x79\x65\x35\x1d\x11\x03",
580             '' => "\x79\x65\x35\x1d\x11\x04",
581             '' => "\x79\x71\x34\x1d\x10\x03",
582             '^' => "\x79\x71\x34\x1d\x11\x03",
583             '' => "\x79\x71\x34\x1d\x11\x04",
584             '' => "\x79\x71\x35\x1d\x10\x03",
585             '_' => "\x79\x71\x35\x1d\x11\x03",
586             '' => "\x79\x71\x35\x1d\x11\x04",
587             '' => "\x79\x72\x34\x1d\x10\x03",
588             '`' => "\x79\x72\x34\x1d\x11\x03",
589             '' => "\x79\x72\x34\x1d\x11\x04",
590             '' => "\x79\x72\x35\x1d\x10\x03",
591             'a' => "\x79\x72\x35\x1d\x11\x03",
592             '' => "\x79\x72\x35\x1d\x11\x04",
593             '' => "\x79\x73\x34\x1b\x10\x03",
594             'b' => "\x79\x73\x34\x1b\x11\x03",
595             '' => "\x79\x73\x34\x1b\x11\x04",
596             '' => "\x79\x73\x34\x1d\x10\x03",
597             'c' => "\x79\x73\x34\x1d\x11\x03",
598             '' => "\x79\x73\x34\x1d\x11\x04",
599             '' => "\x79\x73\x35\x1d\x10\x03",
600             'd' => "\x79\x73\x35\x1d\x11\x03",
601             '' => "\x79\x73\x35\x1d\x11\x04",
602             '' => "\x79\x74\x34\x1d\x10\x03",
603             'e' => "\x79\x74\x34\x1d\x11\x03",
604             '' => "\x79\x74\x34\x1d\x11\x04",
605             '' => "\x79\x74\x35\x1d\x10\x03",
606             'f' => "\x79\x74\x35\x1d\x11\x03",
607             '' => "\x79\x74\x35\x1d\x11\x04",
608             '' => "\x79\x75\x34\x1d\x10\x03",
609             'g' => "\x79\x75\x34\x1d\x11\x03",
610             '' => "\x79\x75\x34\x1d\x11\x04",
611             '' => "\x79\x75\x35\x1d\x10\x03",
612             'h' => "\x79\x75\x35\x1d\x11\x03",
613             '' => "\x79\x75\x35\x1d\x11\x04",
614             '' => "\x79\x81\x34\x1d\x10\x03",
615             'i' => "\x79\x81\x34\x1d\x11\x03",
616             '' => "\x79\x81\x34\x1d\x11\x04",
617             '' => "\x79\x82\x34\x1d\x10\x03",
618             'j' => "\x79\x82\x34\x1d\x11\x03",
619             '' => "\x79\x82\x34\x1d\x11\x04",
620             '' => "\x79\x83\x34\x1d\x10\x03",
621             'k' => "\x79\x83\x34\x1d\x11\x03",
622             '' => "\x79\x83\x34\x1d\x11\x04",
623             '' => "\x79\x84\x34\x1d\x10\x03",
624             'l' => "\x79\x84\x34\x1d\x11\x03",
625             '' => "\x79\x84\x34\x1d\x11\x04",
626             '' => "\x79\x85\x34\x1d\x10\x03",
627             'm' => "\x79\x85\x34\x1d\x11\x03",
628             '' => "\x79\x85\x34\x1d\x11\x04",
629             '' => "\x79\x91\x34\x1d\x10\x03",
630             'n' => "\x79\x91\x34\x1d\x11\x03",
631             '' => "\x79\x91\x34\x1d\x11\x04",
632             '' => "\x79\x91\x35\x1d\x10\x03",
633             'o' => "\x79\x91\x35\x1d\x11\x03",
634             '' => "\x79\x91\x35\x1d\x11\x04",
635             '' => "\x79\x91\x36\x1d\x10\x03",
636             'p' => "\x79\x91\x36\x1d\x11\x03",
637             '' => "\x79\x91\x36\x1d\x11\x04",
638             '' => "\x79\x92\x34\x1d\x10\x03",
639             'q' => "\x79\x92\x34\x1d\x11\x03",
640             '' => "\x79\x92\x34\x1d\x11\x04",
641             '' => "\x79\x92\x35\x1d\x10\x03",
642             'r' => "\x79\x92\x35\x1d\x11\x03",
643             '' => "\x79\x92\x35\x1d\x11\x04",
644             '' => "\x79\x92\x36\x1d\x10\x03",
645             's' => "\x79\x92\x36\x1d\x11\x03",
646             '' => "\x79\x92\x36\x1d\x11\x04",
647             '' => "\x79\x93\x34\x1d\x10\x03",
648             't' => "\x79\x93\x34\x1d\x11\x03",
649             '' => "\x79\x93\x34\x1d\x11\x04",
650             '' => "\x79\x93\x35\x1d\x10\x03",
651             'u' => "\x79\x93\x35\x1d\x11\x03",
652             '' => "\x79\x93\x35\x1d\x11\x04",
653             '' => "\x79\x93\x36\x1d\x10\x03",
654             'v' => "\x79\x93\x36\x1d\x11\x03",
655             '' => "\x79\x93\x36\x1d\x11\x04",
656             '' => "\x79\x94\x34\x1d\x10\x03",
657             'w' => "\x79\x94\x34\x1d\x11\x03",
658             '' => "\x79\x94\x34\x1d\x11\x04",
659             '' => "\x79\x94\x35\x1d\x10\x03",
660             'x' => "\x79\x94\x35\x1d\x11\x03",
661             '' => "\x79\x94\x35\x1d\x11\x04",
662             '' => "\x79\x94\x36\x1d\x10\x03",
663             'y' => "\x79\x94\x36\x1d\x11\x03",
664             '' => "\x79\x94\x36\x1d\x11\x04",
665             '' => "\x79\x95\x34\x1d\x10\x03",
666             'z' => "\x79\x95\x34\x1d\x11\x03",
667             '' => "\x79\x95\x34\x1d\x11\x04",
668             '' => "\x79\x95\x35\x1d\x10\x03",
669             '{' => "\x79\x95\x35\x1d\x11\x03",
670             '' => "\x79\x95\x35\x1d\x11\x04",
671             '' => "\x79\x95\x36\x1d\x10\x03",
672             '|' => "\x79\x95\x36\x1d\x11\x03",
673             '' => "\x79\x95\x36\x1d\x11\x04",
674             '' => "\x79\xa1\x34\x1d\x10\x03",
675             '}' => "\x79\xa1\x34\x1d\x11\x03",
676             '' => "\x79\xa1\x34\x1d\x11\x04",
677             '' => "\x79\xa2\x34\x1d\x10\x03",
678             '~' => "\x79\xa2\x34\x1d\x11\x03",
679             '' => "\x79\xa2\x34\x1d\x11\x04",
680             '' => "\x79\xa3\x34\x1d\x10\x03",
681             '' => "\x79\xa3\x34\x1d\x11\x03",
682             '' => "\x79\xa3\x34\x1d\x11\x04",
683             '' => "\x79\xa4\x34\x1d\x10\x03",
684             '' => "\x79\xa4\x34\x1d\x11\x03",
685             '' => "\x79\xa4\x34\x1d\x11\x04",
686             '' => "\x79\xa5\x34\x1d\x10\x03",
687             '' => "\x79\xa5\x34\x1d\x11\x03",
688             '' => "\x79\xa5\x34\x1d\x11\x04",
689             '' => "\x79\xb1\x34\x1b\x10\x03",
690             '' => "\x79\xb1\x34\x1b\x11\x03",
691             '' => "\x79\xb1\x34\x1b\x11\x04",
692             '' => "\x79\xb1\x34\x1d\x10\x03",
693             '' => "\x79\xb1\x34\x1d\x11\x03",
694             '' => "\x79\xb1\x34\x1d\x11\x04",
695             '' => "\x79\xb3\x34\x1b\x10\x03",
696             '' => "\x79\xb3\x34\x1b\x11\x03",
697             '' => "\x79\xb3\x34\x1b\x11\x04",
698             '' => "\x79\xb3\x34\x1d\x10\x03",
699             '' => "\x79\xb3\x34\x1d\x11\x03",
700             '' => "\x79\xb3\x34\x1d\x11\x04",
701             '' => "\x79\xb5\x34\x1b\x10\x03",
702             '' => "\x79\xb5\x34\x1b\x11\x03",
703             '' => "\x79\xb5\x34\x1b\x11\x04",
704             '' => "\x79\xb5\x34\x1d\x10\x03",
705             '' => "\x79\xb5\x34\x1d\x11\x03",
706             '' => "\x79\xb5\x34\x1d\x11\x04",
707             '' => "\x79\xc1\x34\x1d\x10\x03",
708             '' => "\x79\xc1\x34\x1d\x11\x03",
709             '' => "\x79\xc1\x34\x1d\x11\x04",
710             '' => "\x79\xc2\x34\x1d\x10\x03",
711             '' => "\x79\xc2\x34\x1d\x11\x03",
712             '' => "\x79\xc2\x34\x1d\x11\x04",
713             '' => "\x79\xc3\x34\x1d\x10\x03",
714             '' => "\x79\xc3\x34\x1d\x11\x03",
715             '' => "\x79\xc3\x34\x1d\x11\x04",
716             '' => "\x79\xc4\x34\x1d\x10\x03",
717             '' => "\x79\xc4\x34\x1d\x11\x03",
718             '' => "\x79\xc4\x34\x1d\x11\x04",
719             '' => "\x79\xc5\x34\x1d\x10\x03",
720             '' => "\x79\xc5\x34\x1d\x11\x03",
721             '' => "\x79\xc5\x34\x1d\x11\x04",
722             '' => "\x79\xd1\x34\x1b\x10\x03",
723             '' => "\x79\xd1\x34\x1b\x11\x03",
724             '' => "\x79\xd1\x34\x1d\x10\x03",
725             '' => "\x79\xd1\x34\x1d\x11\x03",
726             '' => "\x79\xd1\x34\x1d\x11\x04",
727             '' => "\x79\xd2\x34\x1d\x10\x03",
728             '' => "\x79\xd2\x34\x1d\x11\x03",
729             '' => "\x79\xd4\x34\x1d\x10\x03",
730             '' => "\x79\xd4\x34\x1d\x11\x03",
731             '' => "\x79\xd5\x34\x1d\x10\x03",
732             '' => "\x79\xd5\x34\x1d\x11\x03",
733             '' => "\x79\xd5\x34\x1d\x11\x04",
734             '' => "\x79\xd6\x34\x1d\x10\x03",
735             '' => "\x79\xd6\x34\x1d\x11\x03",
736             '' => "\x79\xd6\x34\x1d\x11\x04",
737             'T' => "\x79\xd7\x34\x1c\x10\x03",
738             'R' => "\x79\xd7\x34\x1c\x11\x03",
739             'U' => "\x79\xd7\x35\x1c\x10\x03",
740             'S' => "\x79\xd7\x35\x1c\x11\x03",
741             '[' => "\x79\xd8\x34\x1a\x11\x03",
742             '' => "\x79\xd8\x34\x1a\x11\x04",
743             'V' => "\x7a\x41\x32\x14\x0a\x01",
744             'W' => "\x7a\x42\x32\x14\x0a\x01",
745             'X' => "\x7a\x43\x32\x14\x0a\x01",
746             'Y' => "\x7a\x44\x32\x14\x0a\x01",
747             'Z' => "\x7a\x45\x32\x14\x0a\x01",
748             '' => "\xfe\xfc\x32\x14\x0a\x01",
749             );
750              
751 0 0   0   0 sub _getOrder { wantarray ? %Order : \%Order }
752              
753             sub _getClass($) {
754 519     519   926 my $w = ord shift; # weight
755             return
756 519 100       4146 $w < 0x70 ? 0 : # ignorable
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    100          
    50          
757             $w == 0x70 ? 1 : # space
758             $w == 0x71 ? 2 : # kijutsu kigou : descriptive symbols
759             $w == 0x72 ? 3 : # kakko kigou : quotes and parentheses
760             $w == 0x73 ? 4 : # gakujutsu kigou : math. operators and sci. symbols
761             $w == 0x74 ? 5 : # ippan kigou : general symbols
762             $w == 0x75 ? 6 : # unit symbols
763             $w == 0x76 ? 7 : # arabic digits
764             $w == 0x77 ? 8 : # ooji kigou : Greek and Cyrillic alphabets
765             $w == 0x78 ? 9 : # Latin alphabets
766             $w == 0x79 ? 10 : # kana
767             $w <= 0xfc ? 11 : # kanji
768             12 ; # geta
769             }
770             sub getClass { # method for testing _getClass()
771 489     489 0 10589 my $self = shift;
772 489         989 my $key = $self->getSortKey(shift);
773 489         1456 return _getClass($key);
774             }
775              
776             my %Replaced;
777             my @Replaced = qw( [ T R U S );
778             @Replaced{@Replaced} = (1) x @Replaced;
779              
780             sub _replaced($$) {
781 492     492   671 my $c = shift; # current element
782 492         1015 my $p = unpack('n', shift);
783             # weight at the 1st level of the previous element
784 492 50 33     1966 return unless 0x7941 <= $p && $p <= 0x79d6;
785              
786 492         637 my $d = $p % 16; # dan : a-i-u-e-o or others
787 492         802 my $n = pack('n', $p);
788             return
789 492 100 66     2389 $c eq '['
    50 33        
    50          
    100          
    100          
    100          
    100          
    100          
790             ? "\x79".chr($d == 6 ? 0xd6 : 0x40 + $d)."\x34\x1a\x11\x03" :
791             $c eq ''
792             ? "\x79".chr($d == 6 ? 0xd6 : 0x40 + $d)."\x34\x1a\x11\x04" :
793             $c eq 'T'
794             ? "$n\x34\x1c\x10\x03" :
795             $c eq 'R'
796             ? "$n\x34\x1c\x11\x03" :
797             $c eq 'U' && # has Daku Hiragana
798             $n =~ /^\x79[\x51-\x55\x61-\x65\x71-\x75\x91-\x95]/
799             ? "$n\x35\x1c\x10\x03" :
800             $c eq 'S' && # has Daku Katakana
801             $n =~ /^\x79[\x43\x51-\x55\x61-\x65\x71-\x75\x91-\x95]/
802             ? "$n\x35\x1c\x11\x03" :
803             undef;
804             }
805              
806             sub _length {
807 0     0   0 my $str = shift;
808 0         0 0 + $str =~ s/[\x81-\x9F\xE0-\xFC][\x00-\xFF]|[\x00-\xFF]//g;
809             }
810              
811             sub getWtCJK {
812 25507     25507 0 28154 my $self = shift;
813 25507         29900 my $c = shift;
814 25507 100       45941 if ($self->{kanji} == 3) {
815 4         5 my $u = &{ $self->{tounicode} }($c);
  4         9  
816 4 50 33     32 croak "A passed codepoint of kanji is outside CJK Unified Ideographs"
817             unless 0x4E00 <= $u && $u <= 0x9FFF;
818 4         5 my $d = $u - 0x4E00;
819 4         19 chr(int($d / 192) + 0x80).chr($d % 192 + 0x40)."\x32\x14\x0a\x01";
820             } else {
821 25503         85242 "$c\x32\x14\x0a\x01";
822             }
823             }
824              
825             sub getWt {
826 31161     31161 0 30050 my $self = shift;
827 31161 100       72786 my $str = $self->{preprocess} ? &{ $self->{preprocess} }(shift) : shift;
  7         20  
828 31161         37966 my $kan = $self->{kanji};
829 31161         35365 my $ign = $self->{ignoreChar};
830              
831 31161 50       119682 if ($str !~ m/^(?:$Char)*$/o) {
832 0         0 carp $PACKAGE . " Malformed Shift-JIS character";
833             }
834              
835 31161         31596 my($c, @buf);
836 31161         93235 foreach $c ($str =~ m/$Char/go) {
837 34385 100 100     169185 next unless $Order{$c} || $kan > 1 && $c =~ /^$CJK$/o;
      66        
838 34104 100 100     71831 next if defined $ign && $c =~ /$ign/;
839              
840 34101         32552 my $replaced;
841 34101 100 100     75766 $replaced = _replaced($c, $buf[-1]) if $Replaced{$c} && @buf;
842              
843 34101 50       140246 push @buf,
    100          
    100          
844             $replaced ? $replaced :
845             $Order{$c} ? $Order{$c} :
846             $kan > 1 ? $self->getWtCJK($c) : ();
847             }
848 31161 100       105694 return wantarray ? @buf : join('', @buf);
849             }
850              
851             sub getSortKey {
852 31146     31146 1 37561 my $self = shift;
853 31146         50654 my $wt = $self->getWt(shift);
854 31146         42416 my $lev = $self->{level};
855 31146         28220 my @ret;
856              
857 31146 50       85216 ($ret[0] = $wt) =~ tr/\x40-\xff//cd if 0 < $lev;
858 31146 100       71060 ($ret[1] = $wt) =~ tr/\x32-\x36//cd if 1 < $lev;
859 31146 100       67344 ($ret[2] = $wt) =~ tr/\x14-\x1d//cd if 2 < $lev;
860 31146 100       65939 ($ret[3] = $wt) =~ tr/\x0a-\x11//cd if 3 < $lev;
861 31146 100       54491 ($ret[4] = $wt) =~ tr/\x01-\x05//cd if 4 < $lev;
862              
863             # 3rd level
864 31146 100 100     125805 $ret[2] =~ tr/\x15\x16/\x16\x15/
865             if 2 < $lev && $self->{upper_before_lower};
866              
867             # 4th level
868 31146 100 100     106620 $ret[3] =~ tr/\x10\x11/\x11\x10/
869             if 3 < $lev && $self->{katakana_before_hiragana};
870              
871 31146         157277 join "\0\0", @ret[0..$lev-1];
872             }
873              
874 55     55 1 2119 sub cmp { $_[0]->getSortKey($_[1]) cmp $_[0]->getSortKey($_[2]) }
875 272     272 1 2849 sub eq { $_[0]->getSortKey($_[1]) eq $_[0]->getSortKey($_[2]) }
876 5     5 1 15 sub ne { $_[0]->getSortKey($_[1]) ne $_[0]->getSortKey($_[2]) }
877 13250     13250 1 91036 sub gt { $_[0]->getSortKey($_[1]) gt $_[0]->getSortKey($_[2]) }
878 141     141 1 702 sub ge { $_[0]->getSortKey($_[1]) ge $_[0]->getSortKey($_[2]) }
879 850     850 1 32608 sub lt { $_[0]->getSortKey($_[1]) lt $_[0]->getSortKey($_[2]) }
880 140     140 1 838 sub le { $_[0]->getSortKey($_[1]) le $_[0]->getSortKey($_[2]) }
881              
882             sub sort {
883 18     18 1 8544 my $obj = shift;
884 18         21 my(%hyoki);
885 18         205 foreach (@_) {
886 1161         2149 $hyoki{$_} = $obj->getSortKey($_);
887             }
888 18         91 return sort{ $hyoki{$a} cmp $hyoki{$b} } @_;
  6207         8806  
889             }
890              
891             sub sortYomi {
892 1     1 1 3 my $obj = shift;
893 1         3 my (%hyoki, %yomi);
894 1         3 my @str = @_;
895 1         3 foreach (@str) {
896 5         14 $hyoki{ $_->[0] } = $obj->getSortKey($_->[0]);
897 5         13 $yomi{ $_->[1] } = $obj->getSortKey($_->[1]);
898             }
899              
900 8 50       36 return sort {
901 1         5 $yomi{ $a->[1] } cmp $yomi{ $b->[1] }
902             || $hyoki{ $a->[0] } cmp $hyoki{ $b->[0] }
903             } @str;
904             }
905              
906             sub sortDaihyo {
907 1     1 1 219 my $obj = shift;
908 1         3 my (%class, %hyoki, %yomi, %daihyo, %kashira);
909 1         5 my @str = @_;
910 1         3 foreach (@str) {
911 30         67 $hyoki{ $_->[0] } = $obj->getSortKey( $_->[0] ); # string
912 30         66 $yomi{ $_->[1] } = $obj->getSortKey( $_->[1] ); # string
913 30         87 $daihyo{ $_->[1] } = unpack('n', $yomi{ $_->[1]}); # number
914 30         67 $kashira{ $_->[0] } = unpack('n', $hyoki{$_->[0]}); # number
915 30         77 $class{ $_->[0] } = _getClass( $hyoki{$_->[0]} ); # number
916             }
917              
918 1 50 100     6 sort{ $class{ $a->[0] } <=> $class{ $b->[0] }
  113   100     563  
      100        
919             || $daihyo{ $a->[1] } <=> $daihyo{ $b->[1] }
920             || $kashira{$a->[0] } <=> $kashira{$b->[0] }
921             || $yomi{ $a->[1] } cmp $yomi{ $b->[1] }
922             || $hyoki{ $a->[0] } cmp $hyoki{ $b->[0] }
923             } @str;
924             }
925              
926             ##
927             ## int = index(string, substring)
928             ##
929             sub index {
930 15     15 1 19 my $self = shift;
931 15 50       33 my $str = $self->{preprocess} ? &{ $self->{preprocess} }(shift) : shift;
  0         0  
932 15         16 my $sub = shift;
933 15         20 my $byte = $self->{position_in_bytes};
934 15         18 my $kan = $self->{kanji};
935 15         19 my $ign = $self->{ignoreChar};
936 15         19 my $lev = $self->{level};
937              
938 15         30 my @subWt = $self->getWt($sub);
939 15 0       34 return wantarray ? (0,0) : 0 if ! @subWt;
    50          
940 15 0       31 return wantarray ? () : -1 if $str eq '';
    50          
941              
942 15 50       209 if ($str !~ m/^(?:$Char)*$/o) {
943 0         0 carp $PACKAGE . " Malformed Shift-JIS character";
944             }
945              
946 15         19 my $count = 0;
947 15         17 my($c, $prev, @strWt, @strPt);
948 15         220 foreach $c ($str =~ m/$Char/go) {
949 172         163 my $cur;
950 172 50 33     330 next if defined $ign && $c =~ /$ign/;
951 172 100 66     498 if ($Order{$c} || $kan > 1 && $c =~ /^$CJK$/o) {
      66        
952 166 100 66     376 $cur = _replaced($c, $strWt[-1]) if $Replaced{$c} && @strWt;
953 166 50 66     661 $cur ||= $Order{$c} ? $Order{$c} :
    100          
954             $kan > 1 ? $self->getWtCJK($c) : undef;
955             }
956              
957 172 100       287 if ($cur) {
958 166         209 push @strWt, $cur;
959 166         208 push @strPt, $count;
960             }
961 172 50       267 $count += $byte ? length($c) : _length($c);
962              
963 172         341 while (@strWt >= @subWt) {
964 146 100       355 if (_eqArray(\@strWt, \@subWt, $lev)) {
965 12         15 my $pos = $strPt[0];
966 12 50       91 return wantarray ? ($pos, $count-$pos) : $pos;
967             }
968 134         187 shift @strWt;
969 134         376 shift @strPt;
970             }
971             }
972 3 50       25 return wantarray ? () : -1;
973             }
974              
975             ##
976             ## bool _eqArray(arrayref, arrayref, level)
977             ##
978             sub _eqArray($$$) {
979 146     146   169 my $a = shift; # length $a >= length $b;
980 146         136 my $b = shift;
981 146         153 my $len = 1 + shift; # 1 + level
982              
983 146         207 my($c);
984 146         255 foreach $c (0..@$b-1) {
985 167 100       607 return if substr($a->[$c], 0, $len) ne substr($b->[$c], 0, $len);
986             }
987 12         34 return 1;
988             }
989              
990             1;
991              
992             __END__