« lib/Skilletor/URL.pm
↑ Summary
/usr/local/lib/perl5/site_perl/5.44.0/Sub/Exporter/Progressive.pm »
| 1 | package Unicode::Normalize; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | no warnings 'utf8'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '1.32'; | |||||||||||||||||||||||||||
| 11 | 5 | our $PACKAGE = __PACKAGE__; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 5 | our @EXPORT = qw( NFC NFD NFKC NFKD ); | |||||||||||||||||||||||||||
| 14 | 5 | 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 | 5 | 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 | 0 | ▶ | ? sub { return shift } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | : sub { utf8::unicode_to_native(shift) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.7
Branch: 1 branch
Condition33%1/3
$main::IS_ASCII or $] < "5.008"
MC/DC0%0/2
$main::IS_ASCII or $] < "5.008"
$main::IS_ASCII
$] < "5.008"
Truth table33%1/3
A or B
A= $main::IS_ASCIIB= $] < "5.008"
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | *from_native = ($::IS_ASCII || $] < 5.008) | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | ? sub { return shift } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | : sub { utf8::native_to_unicode(shift) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.7
Branch: 1 branch
Condition33%1/3
$main::IS_ASCII or $] < "5.008"
MC/DC0%0/2
$main::IS_ASCII or $] < "5.008"
$main::IS_ASCII
$] < "5.008"
Truth table33%1/3
A or B
A= $main::IS_ASCIIB= $] < "5.008"
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # The .t files are all in terms of Unicode, so xlate to/from native | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub dot_t_pack_U { | ||||||||||||||||||||||||||
|
Subroutine
dot_t_pack_U: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | return pack('U*', map { to_native($_) } @_); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub dot_t_unpack_U { | ||||||||||||||||||||||||||
|
Subroutine
dot_t_unpack_U: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | 0 | return map { from_native($_) } unpack('U*', shift(@_).pack('U*')); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub get_printable_string ($) { | ||||||||||||||||||||||||||
|
Subroutine
get_printable_string: not called CC=2 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 5 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # DeMorgan's laws cause this to mean ascii printables | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return $s if $s =~ /[^[:^ascii:][:^print:]]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | return join " ", map { sprintf "\\x%02x", ord $_ } split "", $s; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub ok ($$;$) { | ||||||||||||||||||||||||||
|
Subroutine
ok: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $count_ref = shift; # Test number in caller | |||||||||||||||||||||||||||
| 68 | 0 | my $p = my $r = shift; | |||||||||||||||||||||||||||
| 69 | 0 | my $x; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $x = shift; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | $p = !defined $x ? !defined $r : !defined $r ? 0 : $r eq $x; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | print $p ? "ok" : "not ok", ' ', ++$$count_ref, "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return if $p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my (undef, $file, $line) = caller(1); | |||||||||||||||||||||||||||
| 80 | 0 | print STDERR "# Failed test $$count_ref at $file line $line\n"; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | return unless defined $x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | print STDERR "# got ", get_printable_string($r), "\n"; | |||||||||||||||||||||||||||
| 85 | 0 | print STDERR "# expected ", get_printable_string($x), "\n"; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 5 | require Exporter; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | ##### The above part is common to XS and PP ##### | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 5 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 93 | 5 | ▶ | use XSLoader (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 5 | XSLoader::load( 'Unicode::Normalize', $VERSION ); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | ##### The below part is common to XS and PP ##### | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | ## | ||||||||||||||||||||||||||||
| 99 | ## normalize | ||||||||||||||||||||||||||||
| 100 | ## | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub FCD ($) { | ||||||||||||||||||||||||||
|
Subroutine
FCD: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my $str = shift; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | return checkFCD($str) ? $str : NFD($str); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 5 | 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
normalize: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 0 | my $form = shift; | |||||||||||||||||||||||||||
| 118 | 0 | my $str = shift; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | if (exists $formNorm{$form}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | return $formNorm{$form}->($str); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 0 | croak($PACKAGE."::normalize: invalid form name: $form"); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | ## | ||||||||||||||||||||||||||||
| 126 | ## partial | ||||||||||||||||||||||||||||
| 127 | ## | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub normalize_partial ($$) { | ||||||||||||||||||||||||||
|
Subroutine
normalize_partial: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if (exists $formNorm{$_[0]}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | my $n = normalize($_[0], $_[1]); | |||||||||||||||||||||||||||
| 132 | 0 | my($p, $u) = splitOnLastStarter($n); | |||||||||||||||||||||||||||
| 133 | 0 | $_[1] = $u; | |||||||||||||||||||||||||||
| 134 | 0 | return $p; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 0 | croak($PACKAGE."::normalize_partial: invalid form name: $_[0]"); | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub NFD_partial ($) { return normalize_partial('NFD', $_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
NFD_partial: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub NFC_partial ($) { return normalize_partial('NFC', $_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
NFC_partial: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub NFKD_partial($) { return normalize_partial('NFKD',$_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
NFKD_partial: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub NFKC_partial($) { return normalize_partial('NFKC',$_[0]) } | ||||||||||||||||||||||||||
|
Subroutine
NFKC_partial: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | ## | ||||||||||||||||||||||||||||
| 145 | ## check | ||||||||||||||||||||||||||||
| 146 | ## | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 5 | 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 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
check: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | my $form = shift; | |||||||||||||||||||||||||||
| 159 | 0 | my $str = shift; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | if (exists $formCheck{$form}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | return $formCheck{$form}->($str); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | 0 | croak($PACKAGE."::check: invalid form name: $form"); | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 5 | 1; | |||||||||||||||||||||||||||
| 167 | __END__ | ||||||||||||||||||||||||||||