line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unicode::Collate::Locale; |
2
|
|
|
|
|
|
|
|
3
|
102
|
|
|
102
|
|
92646
|
use strict; |
|
102
|
|
|
|
|
789
|
|
|
102
|
|
|
|
|
2907
|
|
4
|
102
|
|
|
102
|
|
501
|
use warnings; |
|
102
|
|
|
|
|
195
|
|
|
102
|
|
|
|
|
2433
|
|
5
|
102
|
|
|
102
|
|
483
|
use Carp; |
|
102
|
|
|
|
|
199
|
|
|
102
|
|
|
|
|
10444
|
|
6
|
102
|
|
|
102
|
|
690
|
use base qw(Unicode::Collate); |
|
102
|
|
|
|
|
206
|
|
|
102
|
|
|
|
|
71111
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.28'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $PL_EXT = '.pl'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %LocaleFile = map { ($_, $_) } qw( |
13
|
|
|
|
|
|
|
af ar as az be bn ca cs cu cy da dsb ee eo es et fa fi fil fo gu |
14
|
|
|
|
|
|
|
ha haw he hi hr hu hy ig is ja kk kl kn ko kok lkt ln lt lv |
15
|
|
|
|
|
|
|
mk ml mr mt nb nn nso om or pa pl ro sa se si sk sl sq sr sv |
16
|
|
|
|
|
|
|
ta te th tn to tr uk ur vi vo wae wo yo zh |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
$LocaleFile{'default'} = ''; |
19
|
|
|
|
|
|
|
# aliases |
20
|
|
|
|
|
|
|
$LocaleFile{'bs'} = 'hr'; |
21
|
|
|
|
|
|
|
$LocaleFile{'bs_Cyrl'} = 'sr'; |
22
|
|
|
|
|
|
|
$LocaleFile{'sr_Latn'} = 'hr'; |
23
|
|
|
|
|
|
|
# short file names |
24
|
|
|
|
|
|
|
$LocaleFile{'de__phonebook'} = 'de_phone'; |
25
|
|
|
|
|
|
|
$LocaleFile{'de_AT_phonebook'} = 'de_at_ph'; |
26
|
|
|
|
|
|
|
$LocaleFile{'es__traditional'} = 'es_trad'; |
27
|
|
|
|
|
|
|
$LocaleFile{'fr_CA'} = 'fr_ca'; |
28
|
|
|
|
|
|
|
$LocaleFile{'fi__phonebook'} = 'fi_phone'; |
29
|
|
|
|
|
|
|
$LocaleFile{'si__dictionary'} = 'si_dict'; |
30
|
|
|
|
|
|
|
$LocaleFile{'sv__reformed'} = 'sv_refo'; |
31
|
|
|
|
|
|
|
$LocaleFile{'ug_Cyrl'} = 'ug_cyrl'; |
32
|
|
|
|
|
|
|
$LocaleFile{'zh__big5han'} = 'zh_big5'; |
33
|
|
|
|
|
|
|
$LocaleFile{'zh__gb2312han'} = 'zh_gb'; |
34
|
|
|
|
|
|
|
$LocaleFile{'zh__pinyin'} = 'zh_pin'; |
35
|
|
|
|
|
|
|
$LocaleFile{'zh__stroke'} = 'zh_strk'; |
36
|
|
|
|
|
|
|
$LocaleFile{'zh__zhuyin'} = 'zh_zhu'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my %TypeAlias = qw( |
39
|
|
|
|
|
|
|
phone phonebook |
40
|
|
|
|
|
|
|
phonebk phonebook |
41
|
|
|
|
|
|
|
dict dictionary |
42
|
|
|
|
|
|
|
reform reformed |
43
|
|
|
|
|
|
|
trad traditional |
44
|
|
|
|
|
|
|
big5 big5han |
45
|
|
|
|
|
|
|
gb2312 gb2312han |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _locale { |
49
|
135
|
|
|
135
|
|
1149
|
my $locale = shift; |
50
|
135
|
100
|
|
|
|
504
|
if ($locale) { |
51
|
133
|
|
|
|
|
474
|
$locale = lc $locale; |
52
|
133
|
|
|
|
|
453
|
$locale =~ tr/\-\ \./_/; |
53
|
133
|
100
|
|
|
|
724
|
$locale =~ s/_([0-9a-z]+)\z/$TypeAlias{$1} ? |
|
42
|
|
|
|
|
356
|
|
54
|
|
|
|
|
|
|
"_$TypeAlias{$1}" : "_$1"/e; |
55
|
133
|
100
|
|
|
|
758
|
$LocaleFile{$locale} and return $locale; |
56
|
|
|
|
|
|
|
|
57
|
34
|
|
|
|
|
139
|
my @code = split /_/, $locale; |
58
|
34
|
|
|
|
|
99
|
my $lan = shift @code; |
59
|
34
|
100
|
100
|
|
|
253
|
my $scr = @code && length $code[0] == 4 ? ucfirst shift @code : ''; |
60
|
34
|
100
|
100
|
|
|
158
|
my $reg = @code && length $code[0] < 4 ? uc shift @code : ''; |
61
|
34
|
100
|
|
|
|
101
|
my $var = @code ? shift @code : ''; |
62
|
|
|
|
|
|
|
|
63
|
34
|
|
|
|
|
68
|
my @list; |
64
|
34
|
100
|
|
|
|
174
|
push @list, ( |
65
|
|
|
|
|
|
|
"${lan}_${scr}_${reg}_$var", |
66
|
|
|
|
|
|
|
"${lan}_${scr}__$var", # empty $scr should not be ${lan}__$var. |
67
|
|
|
|
|
|
|
"${lan}_${reg}_$var", # empty $reg may be ${lan}__$var. |
68
|
|
|
|
|
|
|
"${lan}__$var", |
69
|
|
|
|
|
|
|
) if $var ne ''; |
70
|
34
|
|
|
|
|
188
|
push @list, ( |
71
|
|
|
|
|
|
|
"${lan}_${scr}_${reg}", |
72
|
|
|
|
|
|
|
"${lan}_${scr}", |
73
|
|
|
|
|
|
|
"${lan}_${reg}", |
74
|
|
|
|
|
|
|
${lan}, |
75
|
|
|
|
|
|
|
); |
76
|
34
|
|
|
|
|
88
|
for my $loc (@list) { |
77
|
113
|
100
|
|
|
|
406
|
$LocaleFile{$loc} and return $loc; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
14
|
|
|
|
|
49
|
return 'default'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub getlocale { |
84
|
122
|
|
|
122
|
1
|
1650
|
return shift->{accepted_locale}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub locale_version { |
88
|
3
|
|
|
3
|
1
|
16
|
return shift->{locale_version}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _fetchpl { |
92
|
123
|
|
|
123
|
|
284
|
my $accepted = shift; |
93
|
123
|
|
|
|
|
316
|
my $f = $LocaleFile{$accepted}; |
94
|
123
|
100
|
|
|
|
423
|
return if !$f; |
95
|
111
|
|
|
|
|
293
|
$f .= $PL_EXT; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# allow to search @INC |
98
|
|
|
|
|
|
|
# use File::Spec; |
99
|
|
|
|
|
|
|
# my $path = File::Spec->catfile('Unicode', 'Collate', 'Locale', $f); |
100
|
111
|
|
|
|
|
348
|
my $path = "Unicode/Collate/Locale/$f"; |
101
|
111
|
|
|
|
|
83254
|
my $h = do $path; |
102
|
111
|
50
|
|
|
|
670
|
croak "Unicode/Collate/Locale/$f can't be found" if !$h; |
103
|
111
|
|
|
|
|
416
|
return $h; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub new { |
107
|
123
|
|
|
123
|
0
|
9777
|
my $class = shift; |
108
|
123
|
|
|
|
|
675
|
my %hash = @_; |
109
|
123
|
|
|
|
|
564
|
$hash{accepted_locale} = _locale($hash{locale}); |
110
|
|
|
|
|
|
|
|
111
|
123
|
50
|
|
|
|
477
|
if (exists $hash{table}) { |
112
|
0
|
|
|
|
|
0
|
croak "your table can't be used with Unicode::Collate::Locale"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
123
|
|
|
|
|
420
|
my $href = _fetchpl($hash{accepted_locale}); |
116
|
123
|
|
|
|
|
1046
|
while (my($k,$v) = each %$href) { |
117
|
251
|
100
|
|
|
|
886
|
if (!exists $hash{$k}) { |
|
|
50
|
|
|
|
|
|
118
|
250
|
|
|
|
|
1110
|
$hash{$k} = $v; |
119
|
|
|
|
|
|
|
} elsif ($k eq 'entry') { |
120
|
1
|
|
|
|
|
7
|
$hash{$k} = $v.$hash{$k}; |
121
|
|
|
|
|
|
|
} else { |
122
|
0
|
|
|
|
|
0
|
croak "$k is reserved by $hash{locale}, can't be overwritten"; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} |
125
|
123
|
|
|
|
|
1564
|
return $class->SUPER::new(%hash); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
__END__ |