line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unicode::Normalize; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
BEGIN { |
4
|
12
|
|
|
12
|
|
9674
|
unless ('A' eq pack('U', 0x41)) { |
5
|
|
|
|
|
|
|
die "Unicode::Normalize cannot stringify a Unicode code point\n"; |
6
|
|
|
|
|
|
|
} |
7
|
12
|
50
|
|
|
|
387
|
unless (0x41 == unpack('U', 'A')) { |
8
|
0
|
|
|
|
|
0
|
die "Unicode::Normalize cannot get Unicode code point\n"; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
12
|
|
|
12
|
|
302
|
use 5.006; |
|
12
|
|
|
|
|
52
|
|
13
|
12
|
|
|
12
|
|
64
|
use strict; |
|
12
|
|
|
|
|
48
|
|
|
12
|
|
|
|
|
349
|
|
14
|
12
|
|
|
12
|
|
78
|
use warnings; |
|
12
|
|
|
|
|
23
|
|
|
12
|
|
|
|
|
350
|
|
15
|
12
|
|
|
12
|
|
63
|
use Carp; |
|
12
|
|
|
|
|
27
|
|
|
12
|
|
|
|
|
1237
|
|
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
12
|
|
78
|
no warnings 'utf8'; |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
3109
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '1.26'; |
20
|
|
|
|
|
|
|
our $PACKAGE = __PACKAGE__; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our @EXPORT = qw( NFC NFD NFKC NFKD ); |
23
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
24
|
|
|
|
|
|
|
normalize decompose reorder compose |
25
|
|
|
|
|
|
|
checkNFD checkNFKD checkNFC checkNFKC check |
26
|
|
|
|
|
|
|
getCanon getCompat getComposite getCombinClass |
27
|
|
|
|
|
|
|
isExclusion isSingleton isNonStDecomp isComp2nd isComp_Ex |
28
|
|
|
|
|
|
|
isNFD_NO isNFC_NO isNFC_MAYBE isNFKD_NO isNFKC_NO isNFKC_MAYBE |
29
|
|
|
|
|
|
|
FCD checkFCD FCC checkFCC composeContiguous splitOnLastStarter |
30
|
|
|
|
|
|
|
normalize_partial NFC_partial NFD_partial NFKC_partial NFKD_partial |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
33
|
|
|
|
|
|
|
all => [ @EXPORT, @EXPORT_OK ], |
34
|
|
|
|
|
|
|
normalize => [ @EXPORT, qw/normalize decompose reorder compose/ ], |
35
|
|
|
|
|
|
|
check => [ qw/checkNFD checkNFKD checkNFC checkNFKC check/ ], |
36
|
|
|
|
|
|
|
fast => [ qw/FCD checkFCD FCC checkFCC composeContiguous/ ], |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
## |
40
|
|
|
|
|
|
|
## utilities for tests |
41
|
|
|
|
|
|
|
## |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub pack_U { |
44
|
247
|
|
|
247
|
0
|
3308
|
return pack('U*', @_); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub unpack_U { |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# The empty pack returns an empty UTF-8 string, so the effect is to force |
50
|
|
|
|
|
|
|
# the shifted parameter into being UTF-8. This allows this to work on |
51
|
|
|
|
|
|
|
# Perl 5.6, where there is no utf8::upgrade(). |
52
|
78
|
|
|
78
|
0
|
809
|
return unpack('U*', shift(@_).pack('U*')); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
require Exporter; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
##### The above part is common to XS and PP ##### |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
60
|
12
|
|
|
12
|
|
90
|
use XSLoader (); |
|
12
|
|
|
|
|
42
|
|
|
12
|
|
|
|
|
7659
|
|
61
|
|
|
|
|
|
|
XSLoader::load( 'Unicode::Normalize', $VERSION ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
##### The below part is common to XS and PP ##### |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
## |
66
|
|
|
|
|
|
|
## normalize |
67
|
|
|
|
|
|
|
## |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub FCD ($) { |
70
|
38
|
|
|
38
|
1
|
1026
|
my $str = shift; |
71
|
38
|
100
|
|
|
|
241
|
return checkFCD($str) ? $str : NFD($str); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
our %formNorm = ( |
75
|
|
|
|
|
|
|
NFC => \&NFC, C => \&NFC, |
76
|
|
|
|
|
|
|
NFD => \&NFD, D => \&NFD, |
77
|
|
|
|
|
|
|
NFKC => \&NFKC, KC => \&NFKC, |
78
|
|
|
|
|
|
|
NFKD => \&NFKD, KD => \&NFKD, |
79
|
|
|
|
|
|
|
FCD => \&FCD, FCC => \&FCC, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub normalize($$) |
83
|
|
|
|
|
|
|
{ |
84
|
161
|
|
|
161
|
1
|
1257
|
my $form = shift; |
85
|
161
|
|
|
|
|
241
|
my $str = shift; |
86
|
161
|
50
|
|
|
|
368
|
if (exists $formNorm{$form}) { |
87
|
161
|
|
|
|
|
915
|
return $formNorm{$form}->($str); |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
0
|
croak($PACKAGE."::normalize: invalid form name: $form"); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
## |
93
|
|
|
|
|
|
|
## partial |
94
|
|
|
|
|
|
|
## |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub normalize_partial ($$) { |
97
|
48
|
50
|
|
48
|
1
|
624
|
if (exists $formNorm{$_[0]}) { |
98
|
48
|
|
|
|
|
76
|
my $n = normalize($_[0], $_[1]); |
99
|
48
|
|
|
|
|
165
|
my($p, $u) = splitOnLastStarter($n); |
100
|
48
|
|
|
|
|
78
|
$_[1] = $u; |
101
|
48
|
|
|
|
|
124
|
return $p; |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
0
|
croak($PACKAGE."::normalize_partial: invalid form name: $_[0]"); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
4
|
|
|
4
|
1
|
78
|
sub NFD_partial ($) { return normalize_partial('NFD', $_[0]) } |
107
|
11
|
|
|
11
|
1
|
327
|
sub NFC_partial ($) { return normalize_partial('NFC', $_[0]) } |
108
|
4
|
|
|
4
|
1
|
57
|
sub NFKD_partial($) { return normalize_partial('NFKD',$_[0]) } |
109
|
5
|
|
|
5
|
1
|
103
|
sub NFKC_partial($) { return normalize_partial('NFKC',$_[0]) } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
## |
112
|
|
|
|
|
|
|
## check |
113
|
|
|
|
|
|
|
## |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
our %formCheck = ( |
116
|
|
|
|
|
|
|
NFC => \&checkNFC, C => \&checkNFC, |
117
|
|
|
|
|
|
|
NFD => \&checkNFD, D => \&checkNFD, |
118
|
|
|
|
|
|
|
NFKC => \&checkNFKC, KC => \&checkNFKC, |
119
|
|
|
|
|
|
|
NFKD => \&checkNFKD, KD => \&checkNFKD, |
120
|
|
|
|
|
|
|
FCD => \&checkFCD, FCC => \&checkFCC, |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub check($$) |
124
|
|
|
|
|
|
|
{ |
125
|
30
|
|
|
30
|
1
|
496
|
my $form = shift; |
126
|
30
|
|
|
|
|
88
|
my $str = shift; |
127
|
30
|
50
|
|
|
|
72
|
if (exists $formCheck{$form}) { |
128
|
30
|
|
|
|
|
177
|
return $formCheck{$form}->($str); |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
croak($PACKAGE."::check: invalid form name: $form"); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
__END__ |