Filename | /Users/ether/perl5/perlbrew/perls/36.0/lib/5.36.0/darwin-2level/Unicode/Normalize.pm |
Statements | Executed 27 statements in 6.20ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 24µs | 24µs | BEGIN@3 | Unicode::Normalize::
1 | 1 | 1 | 18µs | 22µs | BEGIN@4 | Unicode::Normalize::
1 | 1 | 1 | 8µs | 42µs | BEGIN@5 | Unicode::Normalize::
1 | 1 | 1 | 7µs | 10µs | BEGIN@57 | Unicode::Normalize::
1 | 1 | 1 | 7µs | 41µs | BEGIN@6 | Unicode::Normalize::
1 | 1 | 1 | 4µs | 20µs | BEGIN@8 | Unicode::Normalize::
1 | 1 | 1 | 2µs | 2µs | BEGIN@93 | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | FCD | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | NFC_partial | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | NFD_partial | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | NFKC_partial | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | NFKD_partial | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | __ANON__[:36] | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | __ANON__[:37] | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | __ANON__[:40] | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | __ANON__[:41] | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | check | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | dot_t_pack_U | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | dot_t_unpack_U | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | get_printable_string | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | normalize | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | normalize_partial | Unicode::Normalize::
0 | 0 | 0 | 0s | 0s | ok | Unicode::Normalize::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Unicode::Normalize; | ||||
2 | |||||
3 | 2 | 40µs | 1 | 24µs | # spent 24µs within Unicode::Normalize::BEGIN@3 which was called:
# once (24µs+0s) by Mojo::Util::BEGIN@22 at line 3 # spent 24µs making 1 call to Unicode::Normalize::BEGIN@3 |
4 | 2 | 33µs | 2 | 26µs | # spent 22µs (18+4) within Unicode::Normalize::BEGIN@4 which was called:
# once (18µs+4µs) by Mojo::Util::BEGIN@22 at line 4 # spent 22µs making 1 call to Unicode::Normalize::BEGIN@4
# spent 4µs making 1 call to strict::import |
5 | 2 | 29µs | 2 | 76µs | # spent 42µs (8+34) within Unicode::Normalize::BEGIN@5 which was called:
# once (8µs+34µs) by Mojo::Util::BEGIN@22 at line 5 # spent 42µs making 1 call to Unicode::Normalize::BEGIN@5
# spent 34µs making 1 call to warnings::import |
6 | 2 | 26µs | 2 | 75µs | # spent 41µs (7+34) within Unicode::Normalize::BEGIN@6 which was called:
# once (7µs+34µs) by Mojo::Util::BEGIN@22 at line 6 # spent 41µs making 1 call to Unicode::Normalize::BEGIN@6
# spent 34µs making 1 call to Exporter::import |
7 | |||||
8 | 2 | 223µs | 2 | 36µs | # spent 20µs (4+16) within Unicode::Normalize::BEGIN@8 which was called:
# once (4µs+16µs) by Mojo::Util::BEGIN@22 at line 8 # spent 20µs making 1 call to Unicode::Normalize::BEGIN@8
# spent 16µs making 1 call to warnings::unimport |
9 | |||||
10 | 1 | 1µs | our $VERSION = '1.31'; | ||
11 | 1 | 1µs | our $PACKAGE = __PACKAGE__; | ||
12 | |||||
13 | 1 | 2µs | our @EXPORT = qw( NFC NFD NFKC NFKD ); | ||
14 | 1 | 3µs | our @EXPORT_OK = qw( | ||
15 | normalize decompose reorder compose | ||||
16 | checkNFD checkNFKD checkNFC checkNFKC check | ||||
17 | getCanon getCompat getComposite getCombinClass | ||||
18 | isExclusion isSingleton isNonStDecomp isComp2nd isComp_Ex | ||||
19 | isNFD_NO isNFC_NO isNFC_MAYBE isNFKD_NO isNFKC_NO isNFKC_MAYBE | ||||
20 | FCD checkFCD FCC checkFCC composeContiguous splitOnLastStarter | ||||
21 | normalize_partial NFC_partial NFD_partial NFKC_partial NFKD_partial | ||||
22 | ); | ||||
23 | 1 | 7µs | our %EXPORT_TAGS = ( | ||
24 | all => [ @EXPORT, @EXPORT_OK ], | ||||
25 | normalize => [ @EXPORT, qw/normalize decompose reorder compose/ ], | ||||
26 | check => [ qw/checkNFD checkNFKD checkNFC checkNFKC check/ ], | ||||
27 | fast => [ qw/FCD checkFCD FCC checkFCC composeContiguous/ ], | ||||
28 | ); | ||||
29 | |||||
30 | ## | ||||
31 | ## utilities for tests | ||||
32 | ## | ||||
33 | |||||
34 | # No EBCDIC support on early perls | ||||
35 | *to_native = ($::IS_ASCII || $] < 5.008) | ||||
36 | ? sub { return shift } | ||||
37 | 1 | 4µs | : sub { utf8::unicode_to_native(shift) }; | ||
38 | |||||
39 | *from_native = ($::IS_ASCII || $] < 5.008) | ||||
40 | ? sub { return shift } | ||||
41 | 1 | 1µs | : sub { utf8::native_to_unicode(shift) }; | ||
42 | |||||
43 | # The .t files are all in terms of Unicode, so xlate to/from native | ||||
44 | sub dot_t_pack_U { | ||||
45 | return pack('U*', map { to_native($_) } @_); | ||||
46 | } | ||||
47 | |||||
48 | sub dot_t_unpack_U { | ||||
49 | |||||
50 | # The empty pack returns an empty UTF-8 string, so the effect is to force | ||||
51 | # the shifted parameter into being UTF-8. This allows this to work on | ||||
52 | # Perl 5.6, where there is no utf8::upgrade(). | ||||
53 | 1 | 2µs | return map { from_native($_) } unpack('U*', shift(@_).pack('U*')); # spent 2µs making 1 call to main::CORE:pack | ||
54 | } | ||||
55 | |||||
56 | sub get_printable_string ($) { | ||||
57 | 2 | 185µs | 2 | 13µs | # spent 10µs (7+3) within Unicode::Normalize::BEGIN@57 which was called:
# once (7µs+3µs) by Mojo::Util::BEGIN@22 at line 57 # spent 10µs making 1 call to Unicode::Normalize::BEGIN@57
# spent 3µs making 1 call to bytes::import |
58 | my $s = shift; | ||||
59 | |||||
60 | # DeMorgan's laws cause this to mean ascii printables | ||||
61 | return $s if $s =~ /[^[:^ascii:][:^print:]]/; | ||||
62 | |||||
63 | return join " ", map { sprintf "\\x%02x", ord $_ } split "", $s; | ||||
64 | } | ||||
65 | |||||
66 | sub ok ($$;$) { | ||||
67 | my $count_ref = shift; # Test number in caller | ||||
68 | my $p = my $r = shift; | ||||
69 | my $x; | ||||
70 | if (@_) { | ||||
71 | $x = shift; | ||||
72 | $p = !defined $x ? !defined $r : !defined $r ? 0 : $r eq $x; | ||||
73 | } | ||||
74 | |||||
75 | print $p ? "ok" : "not ok", ' ', ++$$count_ref, "\n"; | ||||
76 | |||||
77 | return if $p; | ||||
78 | |||||
79 | my (undef, $file, $line) = caller(1); | ||||
80 | print STDERR "# Failed test $$count_ref at $file line $line\n"; | ||||
81 | |||||
82 | return unless defined $x; | ||||
83 | |||||
84 | print STDERR "# got ", get_printable_string($r), "\n"; | ||||
85 | print STDERR "# expected ", get_printable_string($x), "\n"; | ||||
86 | } | ||||
87 | |||||
88 | 1 | 1µs | require Exporter; | ||
89 | |||||
90 | ##### The above part is common to XS and PP ##### | ||||
91 | |||||
92 | 1 | 9µs | our @ISA = qw(Exporter); | ||
93 | 2 | 484µs | 1 | 2µs | # spent 2µs within Unicode::Normalize::BEGIN@93 which was called:
# once (2µs+0s) by Mojo::Util::BEGIN@22 at line 93 # spent 2µs making 1 call to Unicode::Normalize::BEGIN@93 |
94 | 1 | 5.12ms | 1 | 5.11ms | XSLoader::load( 'Unicode::Normalize', $VERSION ); # spent 5.11ms making 1 call to XSLoader::load |
95 | |||||
96 | ##### The below part is common to XS and PP ##### | ||||
97 | |||||
98 | ## | ||||
99 | ## normalize | ||||
100 | ## | ||||
101 | |||||
102 | sub FCD ($) { | ||||
103 | my $str = shift; | ||||
104 | return checkFCD($str) ? $str : NFD($str); | ||||
105 | } | ||||
106 | |||||
107 | 1 | 6µs | our %formNorm = ( | ||
108 | NFC => \&NFC, C => \&NFC, | ||||
109 | NFD => \&NFD, D => \&NFD, | ||||
110 | NFKC => \&NFKC, KC => \&NFKC, | ||||
111 | NFKD => \&NFKD, KD => \&NFKD, | ||||
112 | FCD => \&FCD, FCC => \&FCC, | ||||
113 | ); | ||||
114 | |||||
115 | sub normalize($$) | ||||
116 | { | ||||
117 | my $form = shift; | ||||
118 | my $str = shift; | ||||
119 | if (exists $formNorm{$form}) { | ||||
120 | return $formNorm{$form}->($str); | ||||
121 | } | ||||
122 | croak($PACKAGE."::normalize: invalid form name: $form"); | ||||
123 | } | ||||
124 | |||||
125 | ## | ||||
126 | ## partial | ||||
127 | ## | ||||
128 | |||||
129 | sub normalize_partial ($$) { | ||||
130 | if (exists $formNorm{$_[0]}) { | ||||
131 | my $n = normalize($_[0], $_[1]); | ||||
132 | my($p, $u) = splitOnLastStarter($n); | ||||
133 | $_[1] = $u; | ||||
134 | return $p; | ||||
135 | } | ||||
136 | croak($PACKAGE."::normalize_partial: invalid form name: $_[0]"); | ||||
137 | } | ||||
138 | |||||
139 | sub NFD_partial ($) { return normalize_partial('NFD', $_[0]) } | ||||
140 | sub NFC_partial ($) { return normalize_partial('NFC', $_[0]) } | ||||
141 | sub NFKD_partial($) { return normalize_partial('NFKD',$_[0]) } | ||||
142 | sub NFKC_partial($) { return normalize_partial('NFKC',$_[0]) } | ||||
143 | |||||
144 | ## | ||||
145 | ## check | ||||
146 | ## | ||||
147 | |||||
148 | 1 | 4µs | our %formCheck = ( | ||
149 | NFC => \&checkNFC, C => \&checkNFC, | ||||
150 | NFD => \&checkNFD, D => \&checkNFD, | ||||
151 | NFKC => \&checkNFKC, KC => \&checkNFKC, | ||||
152 | NFKD => \&checkNFKD, KD => \&checkNFKD, | ||||
153 | FCD => \&checkFCD, FCC => \&checkFCC, | ||||
154 | ); | ||||
155 | |||||
156 | sub check($$) | ||||
157 | { | ||||
158 | my $form = shift; | ||||
159 | my $str = shift; | ||||
160 | if (exists $formCheck{$form}) { | ||||
161 | return $formCheck{$form}->($str); | ||||
162 | } | ||||
163 | croak($PACKAGE."::check: invalid form name: $form"); | ||||
164 | } | ||||
165 | |||||
166 | 1 | 20µs | 1; | ||
167 | __END__ |