blib/lib/Unicode/Collate.pm

filter: Statementstmt 97.5% 524 / 537 Branchbran 90.9% 311 / 342 Conditioncond 85.9% 195 / 227 MC/DCmcdc 73.6% 92 / 125 Subroutinesub 96.7% 60 / 62 Podpod 65.5% 19 / 29 totaltotal 90.8% 1201 / 1322 CC 261 SCAR 32.8
CC
261
Cov
93%
index
51.1
splitEnt
44.0
parseAtmark
35.8
CRAP 26.5
↑ Summary blib/lib/Unicode/Collate/Locale.pm »
1 package Unicode::Collate;
2  
3 139 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 139 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 139 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 139 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 139 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 139 ▶no warnings 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 139 our $VERSION = '1.31';
12 139 our $PACKAGE = __PACKAGE__;
13  
14 ### begin XS only ###
15 139 ▶use XSLoader ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 139 XSLoader::load('Unicode::Collate', $VERSION);
17 ### end XS only ###
18  
19 139 my @Path = qw(Unicode Collate);
20 139 my $KeyFile = 'allkeys.txt';
21  
22 # Perl's boolean
23 139 ▶use constant TRUE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 139 ▶use constant FALSE => "";
Subroutine BEGIN: called CC=1 SCAR=0.0
25 139 ▶use constant NOMATCHPOS => -1;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # A coderef to get combining class imported from Unicode::Normalize
28 # (i.e. \&Unicode::Normalize::getCombinClass).
29 # This is also used as a HAS_UNICODE_NORMALIZE flag.
30 139 my $CVgetCombinClass;
31  
32 # Supported Levels
33 139 ▶use constant MinLevel => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 139 ▶use constant MaxLevel => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # Minimum weights at level 2 and 3, respectively
37 139 ▶use constant Min2Wt => 0x20;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 139 ▶use constant Min3Wt => 0x02;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 # Shifted weight at 4th level
41 139 ▶use constant Shift4Wt => 0xFFFF;
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # A boolean for Variable and 16-bit weights at 4 levels of Collation Element
44 139 ▶use constant VCE_TEMPLATE => 'Cn4';
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # A sort key: 16-bit weights
47 139 ▶use constant KEY_TEMPLATE => 'n*';
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 # The tie-breaking: 32-bit weights
50 139 ▶use constant TIE_TEMPLATE => 'N*';
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 # Level separator in a sort key:
53 # i.e. pack(KEY_TEMPLATE, 0)
54 139 ▶use constant LEVEL_SEP => "\0\0";
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 # As Unicode code point separator for hash keys.
57 # A joined code point string (denoted by JCPS below)
58 # like "65;768" is used for internal processing
59 # instead of Perl's Unicode string like "\x41\x{300}",
60 # as the native code point is different from the Unicode code point
61 # on EBCDIC platform.
62 # This character must not be included in any stringified
63 # representation of an integer.
64 139 ▶use constant CODE_SEP => ';';
Subroutine BEGIN: called CC=1 SCAR=0.0
65 # NOTE: in regex /;/ is used for $jcps!
66  
67 # boolean values of variable weights
68 139 ▶use constant NON_VAR => 0; # Non-Variable character
Subroutine BEGIN: called CC=1 SCAR=0.0
69 139 ▶use constant VAR => 1; # Variable character
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 # specific code points
72 139 ▶use constant Hangul_SIni => 0xAC00;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 139 ▶use constant Hangul_SFin => 0xD7A3;
Subroutine BEGIN: called CC=1 SCAR=0.0
74  
75 # Logical_Order_Exception in PropList.txt
76 139 my $DefaultRearrange = [ 0x0E40..0x0E44, 0x0EC0..0x0EC4 ];
77  
78 # for highestFFFF and minimalFFFE
79 139 my $HighestVCE = pack(VCE_TEMPLATE, 0, 0xFFFE, 0x20, 0x5, 0xFFFF);
80 139 my $minimalVCE = pack(VCE_TEMPLATE, 0, 1, 0x20, 0x5, 0xFFFE);
81  
82 200 ▶sub UCA_Version { '43' }
Subroutine UCA_Version: called CC=1 SCAR=0.0
Pod documented
83  
84 10 ▶sub Base_Unicode_Version { '13.0.0' }
Subroutine Base_Unicode_Version: called CC=1 SCAR=0.0
Pod documented
85  
86 ######
87  
88 my $native_to_unicode = ($::IS_ASCII || $] < 5.008)
89 0 ▶ ? sub { return shift }
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 84884 ▶ : sub { utf8::native_to_unicode(shift) };
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 1 branch
BranchTrueFalseTotal
$main::IS_ASCII || $] < 5.008 ? : 0 139 139
Condition33%1/3
$main::IS_ASCII or $] < "5.008"
l!l&&r!l&&!r
00139
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"
ABresult
1X1
011
000
91  
92 my $unicode_to_native = ($::IS_ASCII || $] < 5.008)
93 0 ▶ ? sub { return shift }
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 2956 ▶ : sub { utf8::unicode_to_native(shift) };
Subroutine __ANON__: called CC=1 SCAR=0.8
Branch: 1 branch
BranchTrueFalseTotal
$main::IS_ASCII || $] < 5.008 ? : 0 139 139
Condition33%1/3
$main::IS_ASCII or $] < "5.008"
l!l&&r!l&&!r
00139
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"
ABresult
1X1
011
000
95  
96 # pack_U() should get Unicode code points.
97 2720 ▶sub pack_U {
Subroutine pack_U: called CC=1 SCAR=0.0
Pod undocumented
98 2720 return pack('U*', map $unicode_to_native->($_), @_);
99 }
100  
101 # unpack_U() should return Unicode code points.
102 59578 ▶sub unpack_U {
Subroutine unpack_U: called CC=1 SCAR=0.0
Pod undocumented
103 59578 return map $native_to_unicode->($_), unpack('U*', shift(@_).pack('U*'));
104 }
105 # for older perl version, pack('U*') generates empty string with utf8 flag.
106  
107 ######
108  
109 139 my (%VariableOK);
110 139 @VariableOK{ qw/
111 blanked non-ignorable shifted shift-trimmed
112 / } = (); # keys lowercased
113  
114 139 our @ChangeOK = qw/
115 alternate backwards level normalization rearrange
116 katakana_before_hiragana upper_before_lower ignore_level2
117 overrideCJK overrideHangul overrideOut preprocess UCA_Version
118 hangul_terminator variable identical highestFFFF minimalFFFE
119 long_contraction
120 /;
121  
122 139 our @ChangeNG = qw/
123 entry mapping table maxlength contraction
124 ignoreChar ignoreName undefChar undefName rewrite
125 versionTable alternateTable backwardsTable forwardsTable
126 rearrangeTable variableTable
127 derivCode normCode rearrangeHash backwardsFlag
128 suppress suppressHash
129 __useXS /; ### XS only
130 # The hash key 'ignored' was deleted at v 0.21.
131 # The hash key 'isShift' was deleted at v 0.23.
132 # The hash key 'combining' was deleted at v 0.24.
133 # The hash key 'entries' was deleted at v 0.30.
134 # The hash key 'L3_ignorable' was deleted at v 0.40.
135  
136 8 ▶sub version {
Subroutine version: called CC=2 SCAR=6.9
Pod documented
137 8 my $self = shift;
138 8 ▶ return $self->{versionTable} || 'unknown';
Condition100%2/2
$self->{'versionTable'} || 'unknown'
l!l
62
MC/DC100%1/1
$self->{'versionTable'} || 'unknown'
$self->{'versionTable'}
Truth table100%2/2
A
A= $self->{'versionTable'}
Aresult
11
00
139 }
140  
141 139 my (%ChangeOK, %ChangeNG);
142 139 @ChangeOK{ @ChangeOK } = ();
143 139 @ChangeNG{ @ChangeNG } = ();
144  
145 823 ▶sub change {
Subroutine change: called CC=7 SCAR=19.8
Pod documented
146 823 my $self = shift;
147 823 my %hash = @_;
148 823 my %old;
149 823 ▶ if (exists $hash{alternate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{"alternate"}) 9 814 823
150 9 ▶ if (exists $hash{variable}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{'variable'}) { } 1 8 9
151 1 delete $hash{alternate};
152 } else {
153 8 $hash{variable} = $hash{alternate};
154 }
155 }
156 823 foreach my $k (keys %hash) {
157 884 ▶ if (exists $ChangeOK{$k}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $ChangeOK{$k}) { } 884 0 884
elsif (exists $ChangeNG{$k}) { } 0 0 0
158 884 $old{$k} = $self->{$k};
159 884 $self->{$k} = $hash{$k};
160 } elsif (exists $ChangeNG{$k}) {
161 0 croak "change of $k via change() is not allowed!";
162 }
163 # else => ignored
164 }
165 823 $self->checkCollator();
166 823 ▶ return wantarray ? %old : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 815 823
167 }
168  
169 1059 ▶sub _checkLevel {
Subroutine _checkLevel: called CC=3 SCAR=11.4
170 1059 my $level = shift;
171 1059 my $key = shift; # 'level' or 'backwards'
172 1059 ▶ MinLevel <= $level or croak sprintf
Branch: 1 branch
BranchTrueFalseTotal
1 <= $level or croak(sprintf("Illegal level %d (in value for key '%s') lower than %d.", $level, $key, 1)) 1059 0 1059
173 "Illegal level %d (in value for key '%s') lower than %d.",
174 $level, $key, MinLevel;
175 1059 ▶ $level <= MaxLevel or croak sprintf
Branch: 1 branch
BranchTrueFalseTotal
$level <= 4 or croak(sprintf("Unsupported level %d (in value for key '%s') higher than %d.", $level, $key, 4)) 1059 0 1059
176 "Unsupported level %d (in value for key '%s') higher than %d.",
177 $level, $key, MaxLevel;
178 }
179  
180 139 my %DerivCode = (
181 8 => \&_derivCE_8,
182 9 => \&_derivCE_9,
183 11 => \&_derivCE_9, # 11 == 9
184 14 => \&_derivCE_14,
185 16 => \&_derivCE_14, # 16 == 14
186 18 => \&_derivCE_18,
187 20 => \&_derivCE_20,
188 22 => \&_derivCE_22,
189 24 => \&_derivCE_24,
190 26 => \&_derivCE_24, # 26 == 24
191 28 => \&_derivCE_24, # 28 == 24
192 30 => \&_derivCE_24, # 30 == 24
193 32 => \&_derivCE_32,
194 34 => \&_derivCE_34,
195 36 => \&_derivCE_36,
196 38 => \&_derivCE_38,
197 40 => \&_derivCE_40,
198 41 => \&_derivCE_40, # 41 == 40
199 43 => \&_derivCE_43,
200 );
201  
202 1043 ▶sub checkCollator {
Subroutine checkCollator: called CC=20 SCAR=30.2
Pod undocumented
203 1043 my $self = shift;
204 1043 _checkLevel($self->{level}, 'level');
205  
206 $self->{derivCode} = $DerivCode{ $self->{UCA_Version} }
207 1043 ▶ or croak "Illegal UCA version (passed $self->{UCA_Version}).";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"derivCode"} = $DerivCode{$self->{"UCA_Version"}} or croak(qq[Illegal UCA version (passed $self->{"UCA_Version"}).]) 1043 0 1043
208  
209 $self->{variable} ||= $self->{alternate} || $self->{variableTable} ||
210 1043 ▶ $self->{alternateTable} || 'shifted';
Condition72%8/11
$self->{"variable"} ||= $self->{"alternate"} || $self->{"variableTable"} || $self->{"alternateTable"} || "shifted"
l!l&&r!l&&!r
8242190
$self->{'alternate'} || $self->{'variableTable'} || $self->{'alternateTable'} || 'shifted'
l!l
1218
$self->{"alternate"} or $self->{"variableTable"} or $self->{"alternateTable"}
l!l&&r!l&&!r
10218
$self->{"alternate"} or $self->{"variableTable"}
l!l&&r!l&&!r
10218
MC/DC0%0/4
$self->{"variable"} ||= $self->{"alternate"} || $self->{"variableTable"} || $self->{"alternateTable"} || "shifted"
$self->{"variable"} $self->{"alternate"} $self->{"variableTable"} $self->{"alternateTable"}
Truth table0%0/5
A ||= B or C or D
A= $self->{"variable"}B= $self->{"alternate"}C= $self->{"variableTable"}D= $self->{"alternateTable"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
211 1043 $self->{variable} = $self->{alternate} = lc($self->{variable});
212 exists $VariableOK{ $self->{variable} }
213 1043 ▶ or croak "$PACKAGE unknown variable parameter name: $self->{variable}";
Branch: 1 branch
BranchTrueFalseTotal
exists $VariableOK{$self->{"variable"}} or croak(qq[$Unicode::Collate::PACKAGE unknown variable parameter name: $self->{"variable"}]) 1043 0 1043
214  
215 1043 ▶ if (! defined $self->{backwards}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $self->{'backwards'}) { } 919 124 1043
elsif (not ref $self->{'backwards'}) { } 11 113 124
216 919 $self->{backwardsFlag} = 0;
217 } elsif (! ref $self->{backwards}) {
218 11 _checkLevel($self->{backwards}, 'backwards');
219 11 $self->{backwardsFlag} = 1 << $self->{backwards};
220 } else {
221 113 my %level;
222 113 $self->{backwardsFlag} = 0;
223 113 for my $b (@{ $self->{backwards} }) {
224 5 _checkLevel($b, 'backwards');
225 5 $level{$b} = 1;
226 }
227 113 for my $v (sort keys %level) {
228 5 $self->{backwardsFlag} += 1 << $v;
229 }
230 }
231  
232 1043 ▶ defined $self->{rearrange} or $self->{rearrange} = [];
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"rearrange"} or $self->{"rearrange"} = [] 1041 2 1043
233 ref $self->{rearrange}
234 1043 ▶ or croak "$PACKAGE: list for rearrangement must be store in ARRAYREF";
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{"rearrange"} or croak("$Unicode::Collate::PACKAGE: list for rearrangement must be store in ARRAYREF") 1043 0 1043
235  
236 # keys of $self->{rearrangeHash} are $self->{rearrange}.
237 1043 $self->{rearrangeHash} = undef;
238  
239 1043 ▶ if (@{ $self->{rearrange} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"rearrange"};}) 13 1030 1043
240 13 @{ $self->{rearrangeHash} }{ @{ $self->{rearrange} } } = ();
241 }
242  
243 1043 $self->{normCode} = undef;
244  
245 1043 ▶ if (defined $self->{normalization}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"normalization"}) 40 1003 1043
246 40 eval { require Unicode::Normalize };
247 40 ▶ $@ and croak "Unicode::Normalize is required to normalize strings";
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("Unicode::Normalize is required to normalize strings") 0 40 40
248  
249 40 ▶ $CVgetCombinClass ||= \&Unicode::Normalize::getCombinClass;
Condition100%2/2
$CVgetCombinClass ||= \&Unicode::Normalize::getCombinClass
l!l
355
MC/DC100%1/1
$CVgetCombinClass ||= \&Unicode::Normalize::getCombinClass
$CVgetCombinClass
Truth table100%2/2
A
A= $CVgetCombinClass
Aresult
11
00
250  
251 40 ▶ if ($self->{normalization} =~ /^(?:NF)D\z/) { # tweak for default
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'normalization'} =~ /^(?:NF)D\z/) { } 32 8 40
elsif ($self->{'normalization'} ne 'prenormalized') { } 7 1 8
252 32 $self->{normCode} = \&Unicode::Normalize::NFD;
253 }
254 elsif ($self->{normalization} ne 'prenormalized') {
255 7 my $norm = $self->{normalization};
256 147 ▶ $self->{normCode} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
257 147 Unicode::Normalize::normalize($norm, shift);
258 7 };
259 7 eval { $self->{normCode}->("") }; # try
260 7 ▶ $@ and croak "$PACKAGE unknown normalization form name: $norm";
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("$Unicode::Collate::PACKAGE unknown normalization form name: $norm") 0 7 7
261 }
262 }
263 1043 return;
264 }
265  
266 sub new
267 220 ▶{
Subroutine new: called CC=24 SCAR=32.1
Pod undocumented
268 220 my $class = shift;
269 220 my $self = bless { @_ }, $class;
270  
271 ### begin XS only ###
272 220 ▶ if (! exists $self->{table} && !defined $self->{rewrite} &&
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'table'} || defined $self->{'rewrite'} || defined $self->{'undefName'} || defined $self->{'ignoreName'} || defined $self->{'undefChar'} || defined $self->{'ignoreChar'}) { } 127 93 220
Condition73%11/15
exists $self->{'table'} || defined $self->{'rewrite'} || defined $self->{'undefName'} || defined $self->{'ignoreName'} || defined $self->{'undefChar'} || defined $self->{'ignoreChar'}
l!l&&r!l&&!r
930127
exists $self->{"table"} or defined $self->{"rewrite"} or defined $self->{"undefName"} or defined $self->{"ignoreName"} or defined $self->{"undefChar"}
l!l&&r!l&&!r
930127
exists $self->{"table"} or defined $self->{"rewrite"} or defined $self->{"undefName"} or defined $self->{"ignoreName"}
l!l&&r!l&&!r
930127
exists $self->{"table"} or defined $self->{"rewrite"} or defined $self->{"undefName"}
l!l&&r!l&&!r
930127
exists $self->{"table"} or defined $self->{"rewrite"}
l!l&&r!l&&!r
921127
MC/DC33%2/6
exists $self->{'table'} || defined $self->{'rewrite'} || defined $self->{'undefName'} || defined $self->{'ignoreName'} || defined $self->{'undefChar'} || defined $self->{'ignoreChar'}
exists $self->{"table"} defined $self->{"rewrite"} defined $self->{"undefName"} defined $self->{"ignoreName"} defined $self->{"undefChar"} defined $self->{'ignoreChar'}
Truth table42%3/7
A or B or C or D or E || F
A= exists $self->{"table"}B= defined $self->{"rewrite"}C= defined $self->{"undefName"}D= defined $self->{"ignoreName"}E= defined $self->{"undefChar"}F= defined $self->{'ignoreChar'}
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
273 !defined $self->{undefName} && !defined $self->{ignoreName} &&
274 !defined $self->{undefChar} && !defined $self->{ignoreChar}) {
275 127 $self->{__useXS} = \&_fetch_simple;
276 } else {
277 93 $self->{__useXS} = undef;
278 }
279 ### end XS only ###
280  
281 # keys of $self->{suppressHash} are $self->{suppress}.
282 220 ▶ if ($self->{suppress} && @{ $self->{suppress} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"suppress"} and @{$self->{"suppress"};}) 6 214 220
Condition66%2/3
$self->{"suppress"} and @{$self->{"suppress"};}
!ll&&!rl&&r
21406
MC/DC50%1/2
$self->{"suppress"} and @{$self->{"suppress"};}
$self->{"suppress"} @{$self->{"suppress"};}
Truth table66%2/3
A and B
A= $self->{"suppress"}B= @{$self->{"suppress"};}
ABresult
0X0
100
111
283 6 @{ $self->{suppressHash} }{ @{ $self->{suppress} } } = ();
284 } # before read_table()
285  
286 # If undef is passed explicitly, no file is read.
287 220 ▶ $self->{table} = $KeyFile if ! exists $self->{table};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"table"} 128 92 220
288 220 ▶ $self->read_table() if defined $self->{table};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"table"} 172 48 220
289  
290 220 ▶ if ($self->{entry}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"entry"}) 151 69 220
291 151 ▶ while ($self->{entry} =~ /([^\n]+)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"entry"} =~ /([^\n]+)/g) 29683 151 29834
292 29683 $self->parseEntry($1, TRUE);
293 }
294 }
295  
296 # only in new(), not in change()
297 220 ▶ $self->{level} ||= MaxLevel;
Condition100%2/2
$self->{"level"} ||= 4
l!l
35185
MC/DC100%1/1
$self->{"level"} ||= 4
$self->{"level"}
Truth table100%2/2
A
A= $self->{"level"}
Aresult
11
00
298 220 ▶ $self->{UCA_Version} ||= UCA_Version();
Condition66%2/3
$self->{"UCA_Version"} ||= UCA_Version()
l!l&&r!l&&!r
261940
MC/DC0%0/2
$self->{"UCA_Version"} ||= UCA_Version()
$self->{"UCA_Version"} UCA_Version()
Truth table66%2/3
A ||= B
A= $self->{"UCA_Version"}B= UCA_Version()
ABresult
1X1
011
000
299  
300 $self->{overrideHangul} = FALSE
301 220 ▶ if ! exists $self->{overrideHangul};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"overrideHangul"} 213 7 220
302 $self->{overrideCJK} = FALSE
303 220 ▶ if ! exists $self->{overrideCJK};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"overrideCJK"} 187 33 220
304 $self->{normalization} = 'NFD'
305 220 ▶ if ! exists $self->{normalization};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"normalization"} 9 211 220
306 $self->{rearrange} = $self->{rearrangeTable} ||
307 ($self->{UCA_Version} <= 11 ? $DefaultRearrange : [])
308 220 ▶ if ! exists $self->{rearrange};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $self->{"rearrange"} 218 2 220
$self->{'UCA_Version'} <= 11 ? : 6 212 218
Condition33%1/3
$self->{'rearrangeTable'} || ($self->{'UCA_Version'} <= 11 ? $DefaultRearrange : [])
l!l&&r!l&&!r
02180
MC/DC0%0/2
$self->{'rearrangeTable'} || ($self->{'UCA_Version'} <= 11 ? $DefaultRearrange : [])
$self->{'rearrangeTable'} ($self->{'UCA_Version'} <= 11 ? $DefaultRearrange : [])
Truth table33%1/3
A || B
A= $self->{'rearrangeTable'}B= ($self->{'UCA_Version'} <= 11 ? $DefaultRearrange : [])
ABresult
1X1
011
000
309 $self->{backwards} = $self->{backwardsTable}
310 220 ▶ if ! exists $self->{backwards};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"backwards"} 213 7 220
311 exists $self->{long_contraction} or $self->{long_contraction}
312 220 ▶ = 22 <= $self->{UCA_Version} && $self->{UCA_Version} <= 24;
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{"long_contraction"} or $self->{"long_contraction"} = 22 <= $self->{"UCA_Version"} && $self->{"UCA_Version"} <= 24 0 220 220
Condition100%3/3
22 <= $self->{'UCA_Version'} && $self->{'UCA_Version'} <= 24
!ll&&!rl&&r
1119910
MC/DC100%2/2
22 <= $self->{'UCA_Version'} && $self->{'UCA_Version'} <= 24
22 <= $self->{'UCA_Version'} $self->{'UCA_Version'} <= 24
Truth table100%3/3
A && B
A= 22 <= $self->{'UCA_Version'}B= $self->{'UCA_Version'} <= 24
ABresult
0X0
100
111
313  
314 # checkCollator() will be called in change()
315 220 $self->checkCollator();
316  
317 220 return $self;
318 }
319  
320 684 ▶sub parseAtmark {
Subroutine parseAtmark: called CC=10 SCAR=35.8
Pod undocumented
321 684 my $self = shift;
322 684 my $line = shift; # after s/^\s*\@//
323  
324 684 ▶ if ($line =~ /^version\s*(\S*)/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($line =~ /^version\s*(\S*)/) { } 172 512 684
elsif ($line =~ /^variable\s+(\S*)/) { } 0 512 512
elsif ($line =~ /^alternate\s+(\S*)/) { } 0 512 512
elsif ($line =~ /^backwards\s+(\S*)/) { } 0 512 512
elsif ($line =~ /^forwards\s+(\S*)/) { } 0 512 512
elsif ($line =~ /^rearrange\s+(.*)/) { } 0 512 512
325 172 ▶ $self->{versionTable} ||= $1;
Condition33%1/3
$self->{"versionTable"} ||= $1
l!l&&r!l&&!r
01720
MC/DC0%0/2
$self->{"versionTable"} ||= $1
$self->{"versionTable"} $1
Truth table33%1/3
A ||= B
A= $self->{"versionTable"}B= $1
ABresult
1X1
011
000
326 }
327 elsif ($line =~ /^variable\s+(\S*)/) { # since UTS #10-9
328 0 ▶ $self->{variableTable} ||= $1;
Condition0%0/3
$self->{"variableTable"} ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"variableTable"} ||= $1
$self->{"variableTable"} $1
Truth table0%0/3
A ||= B
A= $self->{"variableTable"}B= $1
ABresult
1X1
011
000
329 }
330 elsif ($line =~ /^alternate\s+(\S*)/) { # till UTS #10-8
331 0 ▶ $self->{alternateTable} ||= $1;
Condition0%0/3
$self->{"alternateTable"} ||= $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"alternateTable"} ||= $1
$self->{"alternateTable"} $1
Truth table0%0/3
A ||= B
A= $self->{"alternateTable"}B= $1
ABresult
1X1
011
000
332 }
333 elsif ($line =~ /^backwards\s+(\S*)/) {
334 0 push @{ $self->{backwardsTable} }, $1;
335 }
336 elsif ($line =~ /^forwards\s+(\S*)/) { # perhaps no use
337 0 push @{ $self->{forwardsTable} }, $1;
338 }
339 elsif ($line =~ /^rearrange\s+(.*)/) { # (\S*) is NG
340 0 push @{ $self->{rearrangeTable} }, _getHexArray($1);
341 }
342 }
343  
344 172 ▶sub read_table {
Subroutine read_table: called CC=11 SCAR=24.1
Pod undocumented
345 172 my $self = shift;
346  
347 ### begin XS only ###
348 172 ▶ if ($self->{__useXS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__useXS"}) 127 45 172
349 127 my @rest = _fetch_rest(); # complex matter need to parse
350 127 for my $line (@rest) {
351 119888 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 0 119888 119888
352  
353 119888 ▶ if ($line =~ s/^\s*\@//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^\s*\@//) { } 635 119253 119888
354 635 $self->parseAtmark($line);
355 } else {
356 119253 $self->parseEntry($line);
357 }
358 }
359 127 return;
360 }
361 ### end XS only ###
362  
363 45 my($f, $fh);
364 45 foreach my $d (@INC) {
365 90 $f = File::Spec->catfile($d, @Path, $self->{table});
366 90 ▶ last if open($fh, $f);
Branch: 1 branch
BranchTrueFalseTotal
if open $fh, $f 45 45 90
367 45 $f = undef;
368 }
369 45 ▶ if (!defined $f) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f) 0 45 45
370 0 $f = File::Spec->catfile(@Path, $self->{table});
371 0 croak("$PACKAGE: Can't locate $f in \@INC (\@INC contains: @INC)");
372 }
373  
374 45 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 71112 45 71157
375 71112 ▶ next if $line =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 809 70303 71112
376  
377 70303 ▶ if ($line =~ s/^\s*\@//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^\s*\@//) { } 49 70254 70303
378 49 $self->parseAtmark($line);
379 } else {
380 70254 $self->parseEntry($line);
381 }
382 }
383 45 close $fh;
384 }
385  
386  
387 ##
388 ## get $line, parse it, and write an entry in $self
389 ##
390 sub parseEntry
391 219190 ▶{
Subroutine parseEntry: called CC=29 SCAR=33.7
Pod undocumented
392 219190 my $self = shift;
393 219190 my $line = shift;
394 219190 my $tailoring = shift;
395 219190 my($name, $entry, @uv, @key);
396  
397 219190 ▶ if (defined $self->{rewrite}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"rewrite"}) 34764 184426 219190
398 34764 $line = $self->{rewrite}->($line);
399 }
400  
401 219190 ▶ return if $line !~ /^\s*[0-9A-Fa-f]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^\s*[0-9A-Fa-f]/ 101 219089 219190
402  
403 # removes comment and gets name
404 219089 ▶ $name = $1
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ s/[#%]\s*(.*)// 99831 119258 219089
405 if $line =~ s/[#%]\s*(.*)//;
406 219089 ▶ return if defined $self->{undefName} && $name =~ /$self->{undefName}/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"undefName"} and $name =~ /$self->{"undefName"}/ 424 218665 219089
Condition100%3/3
defined $self->{"undefName"} and $name =~ /$self->{"undefName"}/
!ll&&!rl&&r
218244421424
MC/DC100%2/2
defined $self->{"undefName"} and $name =~ /$self->{"undefName"}/
defined $self->{"undefName"} $name =~ /$self->{"undefName"}/
Truth table100%3/3
A and B
A= defined $self->{"undefName"}B= $name =~ /$self->{"undefName"}/
ABresult
0X0
100
111
407  
408 # gets element
409 218665 my($e, $k) = split /;/, $line;
410 218665 ▶ croak "Wrong Entry: <charList> must be separated by ';' from <collElement>"
Branch: 1 branch
BranchTrueFalseTotal
unless $k 0 218665 218665
411 if ! $k;
412  
413 218665 @uv = _getHexArray($e);
414 218665 ▶ return if !@uv;
Branch: 1 branch
BranchTrueFalseTotal
unless @uv 0 218665 218665
415 return if @uv > 1 && $self->{suppressHash} && !$tailoring &&
416 218665 ▶ exists $self->{suppressHash}{$uv[0]};
Branch: 1 branch
BranchTrueFalseTotal
if @uv > 1 and $self->{"suppressHash"} and not $tailoring and exists $self->{"suppressHash"}{$uv[0]} 10 218655 218665
Condition100%9/9
@uv > 1 and $self->{"suppressHash"} and not $tailoring and exists $self->{"suppressHash"}{$uv[0]}
!ll&&!rl&&r
213970468510
@uv > 1 and $self->{"suppressHash"} and not $tailoring
!ll&&!rl&&r
213956144695
@uv > 1 and $self->{"suppressHash"}
!ll&&!rl&&r
911291228274709
MC/DC100%4/4
@uv > 1 and $self->{"suppressHash"} and not $tailoring and exists $self->{"suppressHash"}{$uv[0]}
@uv > 1 $self->{"suppressHash"} not $tailoring exists $self->{"suppressHash"}{$uv[0]}
Truth table100%5/5
A and B and not(C) and D
A= @uv > 1B= $self->{"suppressHash"}C= not $tailoringD= exists $self->{"suppressHash"}{$uv[0]}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
417 218655 $entry = join(CODE_SEP, @uv); # in JCPS
418  
419 218655 ▶ if (defined $self->{undefChar} || defined $self->{ignoreChar}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"undefChar"} or defined $self->{"ignoreChar"}) 1690 216965 218655
Condition100%3/3
defined $self->{"undefChar"} or defined $self->{"ignoreChar"}
l!l&&r!l&&!r
845845216965
MC/DC100%2/2
defined $self->{"undefChar"} or defined $self->{"ignoreChar"}
defined $self->{"undefChar"} defined $self->{"ignoreChar"}
Truth table100%3/3
A or B
A= defined $self->{"undefChar"}B= defined $self->{"ignoreChar"}
ABresult
1X1
011
000
420 1690 my $ele = pack_U(@uv);
421  
422 # regarded as if it were not stored in the table
423 return
424 1690 ▶ if defined $self->{undefChar} && $ele =~ /$self->{undefChar}/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"undefChar"} and $ele =~ /$self->{"undefChar"}/ 4 1686 1690
Condition100%3/3
defined $self->{"undefChar"} and $ele =~ /$self->{"undefChar"}/
!ll&&!rl&&r
8458414
MC/DC100%2/2
defined $self->{"undefChar"} and $ele =~ /$self->{"undefChar"}/
defined $self->{"undefChar"} $ele =~ /$self->{"undefChar"}/
Truth table100%3/3
A and B
A= defined $self->{"undefChar"}B= $ele =~ /$self->{"undefChar"}/
ABresult
0X0
100
111
425  
426 # replaced as completely ignorable
427 $k = '[.0000.0000.0000.0000]'
428 1686 ▶ if defined $self->{ignoreChar} && $ele =~ /$self->{ignoreChar}/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ignoreChar"} and $ele =~ /$self->{"ignoreChar"}/ 4 1682 1686
Condition100%3/3
defined $self->{"ignoreChar"} and $ele =~ /$self->{"ignoreChar"}/
!ll&&!rl&&r
8418414
MC/DC100%2/2
defined $self->{"ignoreChar"} and $ele =~ /$self->{"ignoreChar"}/
defined $self->{"ignoreChar"} $ele =~ /$self->{"ignoreChar"}/
Truth table100%3/3
A and B
A= defined $self->{"ignoreChar"}B= $ele =~ /$self->{"ignoreChar"}/
ABresult
0X0
100
111
429 }
430  
431 # replaced as completely ignorable
432 $k = '[.0000.0000.0000.0000]'
433 218651 ▶ if defined $self->{ignoreName} && $name =~ /$self->{ignoreName}/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ignoreName"} and $name =~ /$self->{"ignoreName"}/ 424 218227 218651
Condition100%3/3
defined $self->{"ignoreName"} and $name =~ /$self->{"ignoreName"}/
!ll&&!rl&&r
217803424424
MC/DC100%2/2
defined $self->{"ignoreName"} and $name =~ /$self->{"ignoreName"}/
defined $self->{"ignoreName"} $name =~ /$self->{"ignoreName"}/
Truth table100%3/3
A and B
A= defined $self->{"ignoreName"}B= $name =~ /$self->{"ignoreName"}/
ABresult
0X0
100
111
434  
435 218651 my $is_L3_ignorable = TRUE;
436  
437 218651 foreach my $arr ($k =~ /\[([^\[\]]+)\]/g) { # SPACEs allowed
438 355577 my $var = $arr =~ /\*/; # exactly /^\*/ but be lenient.
439 355577 my @wt = _getHexArray($arr);
440 355577 push @key, pack(VCE_TEMPLATE, $var, @wt);
441 355577 ▶ $is_L3_ignorable = FALSE
Branch: 1 branch
BranchTrueFalseTotal
if $wt[0] or $wt[1] or $wt[2] 348526 7051 355577
Condition100%6/6
$wt[0] or $wt[1] or $wt[2]
l!l&&r!l&&!r
3483391877051
$wt[0] or $wt[1]
l!l&&r!l&&!r
335089132507238
MC/DC100%3/3
$wt[0] or $wt[1] or $wt[2]
$wt[0] $wt[1] $wt[2]
Truth table100%4/4
A or B or C
A= $wt[0]B= $wt[1]C= $wt[2]
ABCresult
1XX1
01X1
0011
0000
442 if $wt[0] || $wt[1] || $wt[2];
443 # Conformance Test for 3.1.1 and 4.0.0 shows Level 3 ignorable
444 # is completely ignorable.
445 # For expansion, an entry $is_L3_ignorable
446 # if and only if "all" CEs are [.0000.0000.0000].
447 }
448  
449 # mapping: be an array ref or not exists (any false value is disallowed)
450 218651 ▶ $self->{mapping}{$entry} = $is_L3_ignorable ? [] : \@key;
Branch: 1 branch
BranchTrueFalseTotal
$is_L3_ignorable ? : 5281 213370 218651
451  
452 # maxlength: be more than 1 or not exists (any false value is disallowed)
453 218651 ▶ if (@uv > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@uv > 1) 127526 91125 218651
454 127526 ▶ if (!$self->{maxlength}{$uv[0]} || $self->{maxlength}{$uv[0]} < @uv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"maxlength"}{$uv[0]} or $self->{"maxlength"}{$uv[0]} < @uv) 10875 116651 127526
Condition100%3/3
not $self->{"maxlength"}{$uv[0]} or $self->{"maxlength"}{$uv[0]} < @uv
l!l&&r!l&&!r
9973902116651
MC/DC100%2/2
not $self->{"maxlength"}{$uv[0]} or $self->{"maxlength"}{$uv[0]} < @uv
not $self->{"maxlength"}{$uv[0]} $self->{"maxlength"}{$uv[0]} < @uv
Truth table100%3/3
not(A) or B
A= not $self->{"maxlength"}{$uv[0]}B= $self->{"maxlength"}{$uv[0]} < @uv
ABresult
1X1
011
000
455 10875 $self->{maxlength}{$uv[0]} = @uv;
456 }
457 }
458  
459 # contraction: be 1 or not exists (any false value is disallowed)
460 218651 ▶ while (@uv > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@uv > 2) 2171 218651 220822
461 2171 pop @uv;
462 2171 my $fake_entry = join(CODE_SEP, @uv); # in JCPS
463 2171 $self->{contraction}{$fake_entry} = 1;
464 }
465 }
466  
467  
468 sub viewSortKey
469 258 ▶{
Subroutine viewSortKey: called CC=1 SCAR=0.0
Pod documented
470 258 my $self = shift;
471 258 my $str = shift;
472 258 $self->visualizeSortKey($self->getSortKey($str));
473 }
474  
475  
476 sub process
477 59153 ▶{
Subroutine process: called CC=3 SCAR=11.0
Pod undocumented
478 59153 my $self = shift;
479 59153 my $str = shift;
480 59153 my $prep = $self->{preprocess};
481 59153 my $norm = $self->{normCode};
482  
483 59153 ▶ $str = &$prep($str) if ref $prep;
Branch: 1 branch
BranchTrueFalseTotal
if ref $prep 8 59145 59153
484 59153 ▶ $str = &$norm($str) if ref $norm;
Branch: 1 branch
BranchTrueFalseTotal
if ref $norm 421 58732 59153
485 59153 return $str;
486 }
487  
488 ##
489 ## arrayref of JCPS = splitEnt(string to be collated)
490 ## arrayref of arrayref[JCPS, ini_pos, fin_pos] = splitEnt(string, TRUE)
491 ##
492 sub splitEnt
493 59392 ▶{
Subroutine splitEnt: called CC=44 SCAR=37.8
Pod undocumented
494 59392 my $self = shift;
495 59392 my $str = shift;
496 59392 my $wLen = shift; # with Length
497  
498 59392 my $map = $self->{mapping};
499 59392 my $max = $self->{maxlength};
500 59392 my $reH = $self->{rearrangeHash};
501 59392 my $vers = $self->{UCA_Version};
502 59392 ▶ my $ver9 = $vers >= 9 && $vers <= 11;
Condition100%3/3
$vers >= 9 && $vers <= 11
!ll&&!rl&&r
736573521304
MC/DC100%2/2
$vers >= 9 && $vers <= 11
$vers >= 9 $vers <= 11
Truth table100%3/3
A && B
A= $vers >= 9B= $vers <= 11
ABresult
0X0
100
111
503 59392 my $long = $self->{long_contraction};
504 59392 my $uXS = $self->{__useXS}; ### XS only
505  
506 59392 my @buf;
507  
508 # get array of Unicode code point of string.
509 59392 my @src = unpack_U($str);
510  
511 # rearrangement:
512 # Character positions are not kept if rearranged,
513 # then neglected if $wLen is true.
514 59392 ▶ if ($reH && ! $wLen) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reH and not $wLen) 132 59260 59392
Condition100%3/3
$reH and not $wLen
!ll&&!rl&&r
5924614132
MC/DC100%2/2
$reH and not $wLen
$reH not $wLen
Truth table100%3/3
A and not(B)
A= $reHB= not $wLen
ABresult
0X0
100
111
515 132 ▶ for (my $i = 0; $i < @src; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @src) 180 132 312
516 180 ▶ if (exists $reH->{ $src[$i] } && $i + 1 < @src) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$reH{$src[$i]} and $i + 1 < @src) 13 167 180
Condition100%3/3
exists $$reH{$src[$i]} and $i + 1 < @src
!ll&&!rl&&r
163413
MC/DC100%2/2
exists $$reH{$src[$i]} and $i + 1 < @src
exists $$reH{$src[$i]} $i + 1 < @src
Truth table100%3/3
A and B
A= exists $$reH{$src[$i]}B= $i + 1 < @src
ABresult
0X0
100
111
517 13 ($src[$i], $src[$i+1]) = ($src[$i+1], $src[$i]);
518 13 $i++;
519 }
520 }
521 }
522  
523 # remove a code point marked as a completely ignorable.
524 59392 ▶ for (my $i = 0; $i < @src; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @src) 84694 59392 144086
525 84694 ▶ if ($vers <= 20 && _isIllegal($src[$i])) {
Branch: 2 branches
BranchTrueFalseTotal
if ($vers <= 20 and _isIllegal($src[$i])) { } 75 84619 84694
elsif ($ver9) { } 1470 83149 84619
Condition100%3/3
$vers <= 20 and _isIllegal($src[$i])
!ll&&!rl&&r
79806481375
MC/DC100%2/2
$vers <= 20 and _isIllegal($src[$i])
$vers <= 20 _isIllegal($src[$i])
Truth table100%3/3
A and B
A= $vers <= 20B= _isIllegal($src[$i])
ABresult
0X0
100
111
526 75 $src[$i] = undef;
527 } elsif ($ver9) {
528 $src[$i] = undef if exists $map->{ $src[$i] }
529 1470 ▶ ? @{ $map->{ $src[$i] } } == 0
Branch: 2 branches
BranchTrueFalseTotal
if exists $$map{$src[$i]} ? @{$$map{$src[$i]};} == 0 : $uXS && _ignorable_simple($src[$i]) 26 1444 1470
exists $$map{$src[$i]} ? : 337 1133 1470
Condition66%2/3
$uXS and _ignorable_simple($src[$i])
!ll&&!rl&&r
1112210
MC/DC0%0/2
$uXS and _ignorable_simple($src[$i])
$uXS _ignorable_simple($src[$i])
Truth table66%2/3
A and B
A= $uXSB= _ignorable_simple($src[$i])
ABresult
0X0
100
111
530 : $uXS && _ignorable_simple($src[$i]); ### XS only
531 }
532 }
533  
534 59392 ▶ for (my $i = 0; $i < @src; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @src) 73218 59392 132610
535 73218 my $jcps = $src[$i];
536  
537 # skip removed code point
538 73218 ▶ if (! defined $jcps) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $jcps) 197 73021 73218
539 197 ▶ if ($wLen && @buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wLen and @buf) 15 182 197
Condition66%2/3
$wLen and @buf
!ll&&!rl&&r
182015
MC/DC50%1/2
$wLen and @buf
$wLen @buf
Truth table66%2/3
A and B
A= $wLenB= @buf
ABresult
0X0
100
111
540 15 $buf[-1][2] = $i + 1;
541 }
542 197 next;
543 }
544  
545 73021 my $i_orig = $i;
546  
547 # find contraction
548 73021 ▶ if (exists $max->{$jcps}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $max->{$jcps}) 13226 59795 73021
549 13226 my $temp_jcps = $jcps;
550 13226 my $jcpsLen = 1;
551 13226 my $maxLen = $max->{$jcps};
552  
553 13226 ▶ for (my $p = $i + 1; $jcpsLen < $maxLen && $p < @src; $p++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($jcpsLen < $maxLen and $p < @src) 13298 13226 26524
Condition100%3/3
$jcpsLen < $maxLen and $p < @src
!ll&&!rl&&r
9282394413298
MC/DC100%2/2
$jcpsLen < $maxLen and $p < @src
$jcpsLen < $maxLen $p < @src
Truth table100%3/3
A and B
A= $jcpsLen < $maxLenB= $p < @src
ABresult
0X0
100
111
554 13298 ▶ next if ! defined $src[$p];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $src[$p] 26 13272 13298
555 13272 $temp_jcps .= CODE_SEP . $src[$p];
556 13272 $jcpsLen++;
557 13272 ▶ if (exists $map->{$temp_jcps}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map->{$temp_jcps}) 10756 2516 13272
558 10756 $jcps = $temp_jcps;
559 10756 $i = $p;
560 }
561 }
562  
563 # discontiguous contraction with Combining Char (cf. UTS#10, S2.1).
564 # This process requires Unicode::Normalize.
565 # If "normalization" is undef, here should be skipped *always*
566 # (in spite of bool value of $CVgetCombinClass),
567 # since canonical ordering cannot be expected.
568 # Blocked combining character should not be contracted.
569  
570 # $self->{normCode} is false in the case of "prenormalized".
571 13226 ▶ if ($self->{normalization}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"normalization"}) 165 13061 13226
572 165 my $cont = $self->{contraction};
573 165 my $preCC = 0;
574 165 my $preCC_uc = 0;
575 165 my $jcps_uc = $jcps;
576 165 my(@out, @out_uc);
577  
578 165 ▶ for (my $p = $i + 1; $p < @src; $p++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p < @src) 268 132 400
579 268 ▶ next if ! defined $src[$p];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $src[$p] 16 252 268
580 252 my $curCC = $CVgetCombinClass->($src[$p]);
581 252 ▶ last unless $curCC;
Branch: 1 branch
BranchTrueFalseTotal
unless $curCC 33 219 252
582 219 my $tail = CODE_SEP . $src[$p];
583  
584 219 ▶ if ($preCC != $curCC && exists $map->{$jcps.$tail}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preCC != $curCC and exists $$map{$jcps . $tail}) { } 64 155 219
Condition100%3/3
$preCC != $curCC and exists $$map{$jcps . $tail}
!ll&&!rl&&r
415164
MC/DC100%2/2
$preCC != $curCC and exists $$map{$jcps . $tail}
$preCC != $curCC exists $$map{$jcps . $tail}
Truth table100%3/3
A and B
A= $preCC != $curCCB= exists $$map{$jcps . $tail}
ABresult
0X0
100
111
585 64 $jcps .= $tail;
586 64 push @out, $p;
587 } else {
588 155 $preCC = $curCC;
589 }
590  
591 219 ▶ next if !$long;
Branch: 1 branch
BranchTrueFalseTotal
unless $long 100 119 219
592  
593 119 ▶ if ($preCC_uc != $curCC &&
Branch: 1 branch
BranchTrueFalseTotal
if ($preCC_uc != $curCC and exists $$map{$jcps_uc . $tail} || exists $$cont{$jcps_uc . $tail}) { } 79 40 119
Condition83%5/6
$preCC_uc != $curCC and exists $$map{$jcps_uc . $tail} || exists $$cont{$jcps_uc . $tail}
!ll&&!rl&&r
04079
exists $$map{$jcps_uc . $tail} or exists $$cont{$jcps_uc . $tail}
l!l&&r!l&&!r
394040
MC/DC66%2/3
$preCC_uc != $curCC and exists $$map{$jcps_uc . $tail} || exists $$cont{$jcps_uc . $tail}
$preCC_uc != $curCC exists $$map{$jcps_uc . $tail} exists $$cont{$jcps_uc . $tail}
Truth table75%3/4
A and B or C
A= $preCC_uc != $curCCB= exists $$map{$jcps_uc . $tail}C= exists $$cont{$jcps_uc . $tail}
ABCresult
0XX0
1000
11X1
1011
594 (exists $map->{$jcps_uc.$tail} ||
595 exists $cont->{$jcps_uc.$tail})) {
596 79 $jcps_uc .= $tail;
597 79 push @out_uc, $p;
598 } else {
599 40 $preCC_uc = $curCC;
600 }
601 }
602  
603 165 ▶ if (@out_uc && exists $map->{$jcps_uc}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@out_uc and exists $map->{$jcps_uc}) { } 39 126 165
Condition100%3/3
@out_uc and exists $map->{$jcps_uc}
!ll&&!rl&&r
125139
MC/DC100%2/2
@out_uc and exists $map->{$jcps_uc}
@out_uc exists $map->{$jcps_uc}
Truth table100%3/3
A and B
A= @out_ucB= exists $map->{$jcps_uc}
ABresult
0X0
100
111
604 39 $jcps = $jcps_uc;
605 39 $src[$_] = undef for @out_uc;
606 } else {
607 126 $src[$_] = undef for @out;
608 }
609 }
610 }
611  
612 # skip completely ignorable
613 73021 ▶ if (exists $map->{$jcps} ? @{ $map->{$jcps} } == 0 :
Branch: 2 branches
BranchTrueFalseTotal
if (exists $map->{$jcps} ? @{$map->{$jcps};} == 0 : $uXS && !($jcps =~ /;/) && _ignorable_simple($jcps)) 334 72687 73021
exists $map->{$jcps} ? : 33130 39891 73021
Condition83%5/6
$uXS and not $jcps =~ /;/ and _ignorable_simple($jcps)
!ll&&!rl&&r
108092902854
$uXS and not $jcps =~ /;/
!ll&&!rl&&r
10809029082
MC/DC66%2/3
$uXS and not $jcps =~ /;/ and _ignorable_simple($jcps)
$uXS not $jcps =~ /;/ _ignorable_simple($jcps)
Truth table75%3/4
A and not(B) and C
A= $uXSB= not $jcps =~ /;/C= _ignorable_simple($jcps)
ABCresult
0XX0
10X0
1100
1111
614 $uXS && $jcps !~ /;/ && _ignorable_simple($jcps)) { ### XS only
615 334 ▶ if ($wLen && @buf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wLen and @buf) 94 240 334
Condition100%3/3
$wLen and @buf
!ll&&!rl&&r
232894
MC/DC100%2/2
$wLen and @buf
$wLen @buf
Truth table100%3/3
A and B
A= $wLenB= @buf
ABresult
0X0
100
111
616 94 $buf[-1][2] = $i + 1;
617 }
618 334 next;
619 }
620  
621 72687 ▶ push @buf, $wLen ? [$jcps, $i_orig, $i + 1] : $jcps;
Branch: 1 branch
BranchTrueFalseTotal
$wLen ? : 1976 70711 72687
622 }
623 59392 return \@buf;
624 }
625  
626 ##
627 ## VCE = _pack_override(input, codepoint, derivCode)
628 ##
629 12423 ▶sub _pack_override ($$$) {
Subroutine _pack_override: called CC=4 SCAR=13.9
630 12423 my $r = shift;
631 12423 my $u = shift;
632 12423 my $der = shift;
633  
634 12423 ▶ if (ref $r) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $r) { } 1343 11080 12423
elsif (defined $r) { } 8814 2266 11080
635 1343 return pack(VCE_TEMPLATE, NON_VAR, @$r);
636 } elsif (defined $r) {
637 8814 return pack(VCE_TEMPLATE, NON_VAR, $r, Min2Wt, Min3Wt, $u);
638 } else {
639 2266 ▶ $u = 0xFFFD if 0x10FFFF < $u;
Branch: 1 branch
BranchTrueFalseTotal
if 1114111 < $u 4 2262 2266
640 2266 return $der->($u);
641 }
642 }
643  
644 ##
645 ## list of VCE = getWt(JCPS)
646 ##
647 sub getWt
648 72483 ▶{
Subroutine getWt: called CC=34 SCAR=35.3
Pod undocumented
649 72483 my $self = shift;
650 72483 my $u = shift;
651 72483 my $map = $self->{mapping};
652 72483 my $der = $self->{derivCode};
653 72483 my $out = $self->{overrideOut};
654 72483 my $uXS = $self->{__useXS}; ### XS only
655  
656 72483 ▶ return if !defined $u;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $u 0 72483 72483
657 72483 ▶ return $self->varCE($HighestVCE) if $u eq 0xFFFF && $self->{highestFFFF};
Branch: 1 branch
BranchTrueFalseTotal
if $u eq 65535 and $self->{"highestFFFF"} 132 72351 72483
Condition100%3/3
$u eq 65535 and $self->{"highestFFFF"}
!ll&&!rl&&r
72229122132
MC/DC100%2/2
$u eq 65535 and $self->{"highestFFFF"}
$u eq 65535 $self->{"highestFFFF"}
Truth table100%3/3
A and B
A= $u eq 65535B= $self->{"highestFFFF"}
ABresult
0X0
100
111
658 72351 ▶ return $self->varCE($minimalVCE) if $u eq 0xFFFE && $self->{minimalFFFE};
Branch: 1 branch
BranchTrueFalseTotal
if $u eq 65534 and $self->{"minimalFFFE"} 22 72329 72351
Condition100%3/3
$u eq 65534 and $self->{"minimalFFFE"}
!ll&&!rl&&r
722824722
MC/DC100%2/2
$u eq 65534 and $self->{"minimalFFFE"}
$u eq 65534 $self->{"minimalFFFE"}
Truth table100%3/3
A and B
A= $u eq 65534B= $self->{"minimalFFFE"}
ABresult
0X0
100
111
659 72329 ▶ $u = 0xFFFD if $u !~ /;/ && 0x10FFFF < $u && !$out;
Branch: 1 branch
BranchTrueFalseTotal
if not $u =~ /;/ and 1114111 < $u and not $out 6 72323 72329
Condition100%6/6
not $u =~ /;/ and 1114111 < $u and not $out
!ll&&!rl&&r
72251726
not $u =~ /;/ and 1114111 < $u
!ll&&!rl&&r
100206223178
MC/DC100%3/3
not $u =~ /;/ and 1114111 < $u and not $out
not $u =~ /;/ 1114111 < $u not $out
Truth table100%4/4
not(A) and B and not(C)
A= not $u =~ /;/B= 1114111 < $uC= not $out
ABCresult
0XX0
10X0
1100
1111
660  
661 72329 my @ce;
662 72329 ▶ if (exists $map->{$u}) {
Branch: 4 branches
BranchTrueFalseTotal
if (exists $map->{$u}) { } 32644 39685 72329
elsif ($uXS and _exists_simple($u)) { } 16698 22987 39685
elsif (44032 <= $u and $u <= 55203) { } 138 22849 22987
elsif ($out and 1114111 < $u) { } 72 22777 22849
663 32644 @ce = @{ $map->{$u} }; # $u may be a contraction
664 ### begin XS only ###
665 ▶ } elsif ($uXS && _exists_simple($u)) {
Condition100%3/3
$uXS and _exists_simple($u)
!ll&&!rl&&r
107791220816698
MC/DC100%2/2
$uXS and _exists_simple($u)
$uXS _exists_simple($u)
Truth table100%3/3
A and B
A= $uXSB= _exists_simple($u)
ABresult
0X0
100
111
666 16698 @ce = _fetch_simple($u);
667 ### end XS only ###
668 ▶ } elsif (Hangul_SIni <= $u && $u <= Hangul_SFin) {
Condition100%3/3
44032 <= $u and $u <= 55203
!ll&&!rl&&r
177825067138
MC/DC100%2/2
44032 <= $u and $u <= 55203
44032 <= $u $u <= 55203
Truth table100%3/3
A and B
A= 44032 <= $uB= $u <= 55203
ABresult
0X0
100
111
669 138 my $hang = $self->{overrideHangul};
670 138 ▶ if ($hang) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hang) { } 23 115 138
elsif (not defined $hang) { } 10 105 115
671 23 @ce = map _pack_override($_, $u, $der), $hang->($u);
672 } elsif (!defined $hang) {
673 10 @ce = $der->($u);
674 } else {
675 105 my $max = $self->{maxlength};
676 105 my @decH = _decompHangul($u);
677  
678 105 ▶ if (@decH == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@decH == 2) { } 45 60 105
679 45 my $contract = join(CODE_SEP, @decH);
680 45 ▶ @decH = ($contract) if exists $map->{$contract};
Branch: 1 branch
BranchTrueFalseTotal
if exists $map->{$contract} 4 41 45
681 } else { # must be <@decH == 3>
682 60 ▶ if (exists $max->{$decH[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$max{$decH[0]}) 7 53 60
683 7 my $contract = join(CODE_SEP, @decH);
684 7 ▶ if (exists $map->{$contract}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $map->{$contract}) { } 1 6 7
685 1 @decH = ($contract);
686 } else {
687 6 $contract = join(CODE_SEP, @decH[0,1]);
688 6 ▶ exists $map->{$contract} and @decH = ($contract, $decH[2]);
Branch: 1 branch
BranchTrueFalseTotal
exists $map->{$contract} and @decH = ($contract, $decH[2]) 5 1 6
689 }
690 # even if V's ignorable, LT contraction is not supported.
691 # If such a situation were required, NFD should be used.
692 }
693 60 ▶ if (@decH == 3 && exists $max->{$decH[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@decH == 3 and exists $$max{$decH[1]}) 2 58 60
Condition100%3/3
@decH == 3 and exists $$max{$decH[1]}
!ll&&!rl&&r
6522
MC/DC100%2/2
@decH == 3 and exists $$max{$decH[1]}
@decH == 3 exists $$max{$decH[1]}
Truth table100%3/3
A and B
A= @decH == 3B= exists $$max{$decH[1]}
ABresult
0X0
100
111
694 2 my $contract = join(CODE_SEP, @decH[1,2]);
695 2 ▶ exists $map->{$contract} and @decH = ($decH[0], $contract);
Branch: 1 branch
BranchTrueFalseTotal
exists $map->{$contract} and @decH = ($decH[0], $contract) 2 0 2
696 }
697 }
698  
699 @ce = map({
700 105 ▶ exists $map->{$_} ? @{ $map->{$_} } :
Branch: 2 branches
BranchTrueFalseTotal
exists $map->{$_} ? : 121 136 257
$uXS && _exists_simple($_) ? : 100 36 136
Condition66%2/3
$uXS and _exists_simple($_)
!ll&&!rl&&r
360100
MC/DC50%1/2
$uXS and _exists_simple($_)
$uXS _exists_simple($_)
Truth table66%2/3
A and B
A= $uXSB= _exists_simple($_)
ABresult
0X0
100
111
701 $uXS && _exists_simple($_) ? _fetch_simple($_) : ### XS only
702 $der->($_);
703 } @decH);
704 }
705 ▶ } elsif ($out && 0x10FFFF < $u) {
Condition100%3/3
$out and 1114111 < $u
!ll&&!rl&&r
2267410372
MC/DC100%2/2
$out and 1114111 < $u
$out 1114111 < $u
Truth table100%3/3
A and B
A= $outB= 1114111 < $u
ABresult
0X0
100
111
706 72 @ce = map _pack_override($_, $u, $der), $out->($u);
707 } else {
708 22777 my $cjk = $self->{overrideCJK};
709 22777 my $vers = $self->{UCA_Version};
710 22777 ▶ if ($cjk && _isUIdeo($u, $vers)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cjk and _isUIdeo($u, $vers)) { } 11755 11022 22777
elsif ($vers == 8 and defined $cjk and _isUIdeo($u, 0)) { } 96 10926 11022
Condition100%3/3
$cjk and _isUIdeo($u, $vers)
!ll&&!rl&&r
8981204111755
MC/DC100%2/2
$cjk and _isUIdeo($u, $vers)
$cjk _isUIdeo($u, $vers)
Truth table100%3/3
A and B
A= $cjkB= _isUIdeo($u, $vers)
ABresult
0X0
100
111
711 11755 @ce = map _pack_override($_, $u, $der), $cjk->($u);
712 ▶ } elsif ($vers == 8 && defined $cjk && _isUIdeo($u, 0)) {
Condition100%6/6
$vers == 8 and defined $cjk and _isUIdeo($u, 0)
!ll&&!rl&&r
1051141596
$vers == 8 and defined $cjk
!ll&&!rl&&r
1045556511
MC/DC100%3/3
$vers == 8 and defined $cjk and _isUIdeo($u, 0)
$vers == 8 defined $cjk _isUIdeo($u, 0)
Truth table100%4/4
A and B and C
A= $vers == 8B= defined $cjkC= _isUIdeo($u, 0)
ABCresult
0XX0
10X0
1100
1111
713 96 @ce = _uideoCE_8($u);
714 } else {
715 10926 @ce = $der->($u);
716 }
717 }
718 72329 return map $self->varCE($_), @ce;
719 }
720  
721  
722 ##
723 ## string sortkey = getSortKey(string arg)
724 ##
725 sub getSortKey
726 59153 ▶{
Subroutine getSortKey: called CC=17 SCAR=28.4
Pod documented
727 59153 my $self = shift;
728 59153 my $orig = shift;
729 59153 my $str = $self->process($orig);
730 59153 my $rEnt = $self->splitEnt($str); # get an arrayref of JCPS
731 59153 my $vers = $self->{UCA_Version};
732 59153 my $term = $self->{hangul_terminator};
733 59153 my $lev = $self->{level};
734 59153 my $iden = $self->{identical};
735  
736 59153 my @buf; # weight arrays
737 59153 ▶ if ($term) {
Branch: 1 branch
BranchTrueFalseTotal
if ($term) { } 100 59053 59153
738 100 my $preHST = '';
739 100 my $termCE = $self->varCE(pack(VCE_TEMPLATE, NON_VAR, $term, 0,0,0));
740 100 foreach my $jcps (@$rEnt) {
741 # weird things like VL, TL-contraction are not considered!
742 243 my $curHST = join '', map getHST($_, $vers), split /;/, $jcps;
743 243 ▶ if ($preHST && !$curHST || # hangul before non-hangul
Branch: 1 branch
BranchTrueFalseTotal
if ($preHST and not $curHST or $preHST =~ /L\z/ and $curHST =~ /^T/ or $preHST =~ /V\z/ and $curHST =~ /^L/ or $preHST =~ /T\z/ and $curHST =~ /^[LV]/) 25 218 243
Condition80%17/21
$preHST and not $curHST or $preHST =~ /L\z/ and $curHST =~ /^T/ or $preHST =~ /V\z/ and $curHST =~ /^L/ or $preHST =~ /T\z/ and $curHST =~ /^[LV]/
l!l&&r!l&&!r
250218
$preHST and not $curHST or $preHST =~ /L\z/ and $curHST =~ /^T/ or $preHST =~ /V\z/ and $curHST =~ /^L/
l!l&&r!l&&!r
223218
$preHST and not $curHST or $preHST =~ /L\z/ and $curHST =~ /^T/
l!l&&r!l&&!r
220221
$preHST and not $curHST
!ll&&!rl&&r
10911222
$preHST =~ /L\z/ and $curHST =~ /^T/
!ll&&!rl&&r
152690
$preHST =~ /V\z/ and $curHST =~ /^L/
!ll&&!rl&&r
181373
$preHST =~ /T\z/ and $curHST =~ /^[LV]/
!ll&&!rl&&r
21530
MC/DC50%4/8
$preHST and not $curHST or $preHST =~ /L\z/ and $curHST =~ /^T/ or $preHST =~ /V\z/ and $curHST =~ /^L/ or $preHST =~ /T\z/ and $curHST =~ /^[LV]/
$preHST not $curHST $preHST =~ /L\z/ $curHST =~ /^T/ $preHST =~ /V\z/ $curHST =~ /^L/ $preHST =~ /T\z/ $curHST =~ /^[LV]/
Truth table19%6/31
A and not(B) or C and D or E and F or G and H
A= $preHSTB= not $curHSTC= $preHST =~ /L\z/D= $curHST =~ /^T/E= $preHST =~ /V\z/F= $curHST =~ /^L/G= $preHST =~ /T\z/H= $curHST =~ /^[LV]/
ABCDEFGHresult
11XXXXXX1
0X11XXXX1
1011XXXX1
0X0X11XX1
0X1011XX1
100X11XX1
101011XX1
0X0X0X111
0X0X10111
0X100X111
0X1010111
100X0X111
100X10111
10100X111
101010111
0X0X0X0X0
0X0X0X100
0X0X100X0
0X0X10100
0X100X0X0
0X100X100
0X10100X0
0X1010100
100X0X0X0
100X0X100
100X100X0
100X10100
10100X0X0
10100X100
1010100X0
101010100
744 $preHST =~ /L\z/ && $curHST =~ /^T/ ||
745 $preHST =~ /V\z/ && $curHST =~ /^L/ ||
746 $preHST =~ /T\z/ && $curHST =~ /^[LV]/) {
747 25 push @buf, $termCE;
748 }
749 243 $preHST = $curHST;
750 243 push @buf, $self->getWt($jcps);
751 }
752 100 ▶ push @buf, $termCE if $preHST; # end at hangul
Branch: 1 branch
BranchTrueFalseTotal
if $preHST 66 34 100
753 } else {
754 59053 foreach my $jcps (@$rEnt) {
755 70090 push @buf, $self->getWt($jcps);
756 }
757 }
758  
759 59153 my $rkey = $self->mk_SortKey(\@buf); ### XS only
760  
761 59153 ▶ if ($iden || $vers >= 26 && $lev == MaxLevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iden or $vers >= 26 and $lev == 4) 8726 50427 59153
Condition100%6/6
$iden or $vers >= 26 and $lev == 4
l!l&&r!l&&!r
46868050427
$vers >= 26 and $lev == 4
!ll&&!rl&&r
5971444568680
MC/DC100%3/3
$iden or $vers >= 26 and $lev == 4
$iden $vers >= 26 $lev == 4
Truth table100%4/4
A or B and C
A= $idenB= $vers >= 26C= $lev == 4
ABCresult
1XX1
0111
00X0
0100
762 8726 $rkey .= LEVEL_SEP;
763 8726 ▶ $rkey .= pack(TIE_TEMPLATE, unpack_U($str)) if $iden;
Branch: 1 branch
BranchTrueFalseTotal
if $iden 46 8680 8726
764 }
765 59153 return $rkey;
766 }
767  
768  
769 ##
770 ## int compare = cmp(string a, string b)
771 ##
772 7505 ▶sub cmp { $_[0]->getSortKey($_[1]) cmp $_[0]->getSortKey($_[2]) }
Subroutine cmp: called CC=1 SCAR=0.0
Pod documented
773 14478 ▶sub eq { $_[0]->getSortKey($_[1]) eq $_[0]->getSortKey($_[2]) }
Subroutine eq: called CC=1 SCAR=0.0
Pod documented
774 13 ▶sub ne { $_[0]->getSortKey($_[1]) ne $_[0]->getSortKey($_[2]) }
Subroutine ne: called CC=1 SCAR=0.0
Pod documented
775 5619 ▶sub lt { $_[0]->getSortKey($_[1]) lt $_[0]->getSortKey($_[2]) }
Subroutine lt: called CC=1 SCAR=0.0
Pod documented
776 6 ▶sub le { $_[0]->getSortKey($_[1]) le $_[0]->getSortKey($_[2]) }
Subroutine le: called CC=1 SCAR=0.0
Pod documented
777 1659 ▶sub gt { $_[0]->getSortKey($_[1]) gt $_[0]->getSortKey($_[2]) }
Subroutine gt: called CC=1 SCAR=0.0
Pod documented
778 8 ▶sub ge { $_[0]->getSortKey($_[1]) ge $_[0]->getSortKey($_[2]) }
Subroutine ge: called CC=1 SCAR=0.0
Pod documented
779  
780 ##
781 ## list[strings] sorted = sort(list[strings] arg)
782 ##
783 26 ▶sub sort {
Subroutine sort: called CC=1 SCAR=0.0
Pod documented
784 26 my $obj = shift;
785 return
786 318 map { $_->[1] }
787 26 sort{ $a->[0] cmp $b->[0] }
788 map [ $obj->getSortKey($_), $_ ], @_;
789 }
790  
791  
792 ##
793 ## bool _nonIgnorAtLevel(arrayref weights, int level)
794 ##
795 sub _nonIgnorAtLevel($$)
796 2216 ▶{
Subroutine _nonIgnorAtLevel: called CC=3 SCAR=11.0
797 2216 my $wt = shift;
798 2216 ▶ return if ! defined $wt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wt 0 2216 2216
799 2216 my $lv = shift;
800 2216 ▶ return grep($wt->[$_-1] != 0, MinLevel..$lv) ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
grep(($$wt[$_ - 1] != 0), 1 .. $lv) ? : 1877 339 2216
801 }
802  
803 ##
804 ## bool _eqArray(
805 ## arrayref of arrayref[weights] source,
806 ## arrayref of arrayref[weights] substr,
807 ## int level)
808 ## * comparison of graphemes vs graphemes.
809 ## @$source >= @$substr must be true (check it before call this);
810 ##
811 sub _eqArray($$$)
812 893 ▶{
Subroutine _eqArray: called CC=6 SCAR=17.9
813 893 my $source = shift;
814 893 my $substr = shift;
815 893 my $lev = shift;
816  
817 893 for my $g (0..@$substr-1){
818 # Do the $g'th graphemes have the same number of AV weights?
819 1411 ▶ return if @{ $source->[$g] } != @{ $substr->[$g] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$source->[$g];} != @{$substr->[$g];} 38 1373 1411
820  
821 1373 for my $w (0..@{ $substr->[$g] }-1) {
822 1400 for my $v (0..$lev-1) {
823 1994 ▶ return if $source->[$g][$w][$v] != $substr->[$g][$w][$v];
Branch: 1 branch
BranchTrueFalseTotal
if $source->[$g][$w][$v] != $substr->[$g][$w][$v] 711 1283 1994
824 }
825 }
826 }
827 144 return 1;
828 }
829  
830 ##
831 ## (int position, int length)
832 ## int position = index(string, substring, position, [undoc'ed global])
833 ##
834 ## With "global" (only for the list context),
835 ## returns list of arrayref[position, length].
836 ##
837 sub index
838 139 ▶{
Subroutine index: called CC=51 SCAR=39.3
Pod documented
839 139 my $self = shift;
840 $self->{preprocess} and
841 139 ▶ croak "Don't use Preprocess with index(), match(), etc.";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"preprocess"} and croak("Don't use Preprocess with index(), match(), etc.") 12 127 139
842 $self->{normCode} and
843 127 ▶ croak "Don't use Normalization with index(), match(), etc.";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"normCode"} and croak("Don't use Normalization with index(), match(), etc.") 4 123 127
844  
845 123 my $str = shift;
846 123 my $len = length($str);
847 123 my $sub = shift;
848 123 my $subE = $self->splitEnt($sub);
849 123 ▶ my $pos = @_ ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 46 77 123
850 123 ▶ $pos = 0 if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 1 122 123
851 123 my $glob = shift;
852  
853 123 my $lev = $self->{level};
854 my $v2i = $self->{UCA_Version} >= 9 &&
855 123 ▶ $self->{variable} ne 'non-ignorable';
Condition100%3/3
$self->{'UCA_Version'} >= 9 && $self->{'variable'} ne 'non-ignorable'
!ll&&!rl&&r
145104
MC/DC100%2/2
$self->{'UCA_Version'} >= 9 && $self->{'variable'} ne 'non-ignorable'
$self->{'UCA_Version'} >= 9 $self->{'variable'} ne 'non-ignorable'
Truth table100%3/3
A && B
A= $self->{'UCA_Version'} >= 9B= $self->{'variable'} ne 'non-ignorable'
ABresult
0X0
100
111
856  
857 123 ▶ if (! @$subE) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$subE) 6 117 123
858 6 ▶ my $temp = $pos <= 0 ? 0 : $len <= $pos ? $len : $pos;
Branch: 2 branches
BranchTrueFalseTotal
$pos <= 0 ? : 6 0 6
$len <= $pos ? : 0 0 0
859 6 ▶ return $glob
Branch: 2 branches
BranchTrueFalseTotal
$glob ? : 2 4 6
wantarray ? : 3 1 4
860 ? map([$_, 0], $temp..$len)
861 : wantarray ? ($temp,0) : $temp;
862 }
863 117 ▶ $len < $pos
Branch: 2 branches
BranchTrueFalseTotal
$len < $pos and return wantarray ? () : -1 1 116 117
wantarray ? : 1 0 1
864 and return wantarray ? () : NOMATCHPOS;
865 116 ▶ my $strE = $self->splitEnt($pos ? substr($str, $pos) : $str, TRUE);
Branch: 1 branch
BranchTrueFalseTotal
$pos ? : 4 112 116
866 116 ▶ @$strE
Branch: 2 branches
BranchTrueFalseTotal
@$strE or return wantarray ? () : -1 115 1 116
wantarray ? : 1 0 1
867 or return wantarray ? () : NOMATCHPOS;
868  
869 115 my(@strWt, @iniPos, @finPos, @subWt, @g_ret);
870  
871 115 my $last_is_variable;
872 115 for my $vwt (map $self->getWt($_), @$subE) {
873 416 my($var, @wt) = unpack(VCE_TEMPLATE, $vwt);
874 416 my $to_be_pushed = _nonIgnorAtLevel(\@wt,$lev);
875  
876 # "Ignorable (L1, L2) after Variable" since track. v. 9
877 416 ▶ if ($v2i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2i) 384 32 416
878 384 ▶ if ($var) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var) { } 15 369 384
elsif (not $wt[0]) { } 52 317 369
879 15 $last_is_variable = TRUE;
880 }
881 elsif (!$wt[0]) { # ignorable
882 52 ▶ $to_be_pushed = FALSE if $last_is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if $last_is_variable 0 52 52
883 }
884 else {
885 317 $last_is_variable = FALSE;
886 }
887 }
888  
889 416 ▶ if (@subWt && !$var && !$wt[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@subWt and not $var and not $wt[0]) { } 52 364 416
elsif ($to_be_pushed) { } 351 13 364
Condition100%6/6
@subWt and not $var and not $wt[0]
!ll&&!rl&&r
13023452
@subWt and not $var
!ll&&!rl&&r
11713286
MC/DC100%3/3
@subWt and not $var and not $wt[0]
@subWt not $var not $wt[0]
Truth table100%4/4
A and not(B) and not(C)
A= @subWtB= not $varC= not $wt[0]
ABCresult
0XX0
10X0
1100
1111
890 52 ▶ push @{ $subWt[-1] }, \@wt if $to_be_pushed;
Branch: 1 branch
BranchTrueFalseTotal
if $to_be_pushed 41 11 52
891 } elsif ($to_be_pushed) {
892 351 push @subWt, [ \@wt ];
893 }
894 # else ===> skipped
895 }
896  
897 115 my $count = 0;
898 115 my $end = @$strE - 1;
899  
900 115 $last_is_variable = FALSE; # reuse
901 115 ▶ for (my $i = 0; $i <= $end; ) { # no $i++
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $end) 1459 61 1520
902 1459 my $found_base = 0;
903  
904 # fetch a grapheme
905 1459 ▶ while ($i <= $end && $found_base == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $end and $found_base == 0) 1779 1459 3238
Condition100%3/3
$i <= $end and $found_base == 0
!ll&&!rl&&r
8613731779
MC/DC100%2/2
$i <= $end and $found_base == 0
$i <= $end $found_base == 0
Truth table100%3/3
A and B
A= $i <= $endB= $found_base == 0
ABresult
0X0
100
111
906 1779 for my $vwt ($self->getWt($strE->[$i][0])) {
907 1800 my($var, @wt) = unpack(VCE_TEMPLATE, $vwt);
908 1800 my $to_be_pushed = _nonIgnorAtLevel(\@wt,$lev);
909  
910 # "Ignorable (L1, L2) after Variable" since track. v. 9
911 1800 ▶ if ($v2i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v2i) 1733 67 1800
912 1733 ▶ if ($var) {
Branch: 2 branches
BranchTrueFalseTotal
if ($var) { } 316 1417 1733
elsif (not $wt[0]) { } 95 1322 1417
913 316 $last_is_variable = TRUE;
914 }
915 elsif (!$wt[0]) { # ignorable
916 95 ▶ $to_be_pushed = FALSE if $last_is_variable;
Branch: 1 branch
BranchTrueFalseTotal
if $last_is_variable 4 91 95
917 }
918 else {
919 1322 $last_is_variable = FALSE;
920 }
921 }
922  
923 1800 ▶ if (@strWt && !$var && !$wt[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@strWt and not $var and not $wt[0]) { } 114 1686 1800
elsif ($to_be_pushed) { } 1420 266 1686
Condition100%6/6
@strWt and not $var and not $wt[0]
!ll&&!rl&&r
4331253114
@strWt and not $var
!ll&&!rl&&r
1153181367
MC/DC100%3/3
@strWt and not $var and not $wt[0]
@strWt not $var not $wt[0]
Truth table100%4/4
A and not(B) and not(C)
A= @strWtB= not $varC= not $wt[0]
ABCresult
0XX0
10X0
1100
1111
924 114 ▶ push @{ $strWt[-1] }, \@wt if $to_be_pushed;
Branch: 1 branch
BranchTrueFalseTotal
if $to_be_pushed 61 53 114
925 114 $finPos[-1] = $strE->[$i][2];
926 } elsif ($to_be_pushed) {
927 1420 push @strWt, [ \@wt ];
928 1420 ▶ push @iniPos, $found_base ? NOMATCHPOS : $strE->[$i][1];
Branch: 1 branch
BranchTrueFalseTotal
$found_base ? : 5 1415 1420
929 1420 ▶ $finPos[-1] = NOMATCHPOS if $found_base;
Branch: 1 branch
BranchTrueFalseTotal
if $found_base 5 1415 1420
930 1420 push @finPos, $strE->[$i][2];
931 1420 $found_base++;
932 }
933 # else ===> no-op
934 }
935 1779 $i++;
936 }
937  
938 # try to match
939 1459 ▶ while ( @strWt > @subWt || (@strWt == @subWt && $i > $end) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@strWt > @subWt or @strWt == @subWt and $i > $end) 897 1405 2302
Condition100%6/6
@strWt > @subWt or @strWt == @subWt and $i > $end
l!l&&r!l&&!r
819781405
@strWt == @subWt and $i > $end
!ll&&!rl&&r
54685978
MC/DC100%3/3
@strWt > @subWt or @strWt == @subWt and $i > $end
@strWt > @subWt @strWt == @subWt $i > $end
Truth table100%4/4
A or B and C
A= @strWt > @subWtB= @strWt == @subWtC= $i > $end
ABCresult
1XX1
0111
00X0
0100
940 897 ▶ if ($iniPos[0] != NOMATCHPOS &&
Branch: 1 branch
BranchTrueFalseTotal
if ($iniPos[0] != -1 and $finPos[$#subWt] != -1 and &_eqArray(\@strWt, \@subWt, $lev)) 144 753 897
Condition100%6/6
$iniPos[0] != -1 and $finPos[$#subWt] != -1 and &_eqArray(\@strWt, \@subWt, $lev)
!ll&&!rl&&r
4749144
$iniPos[0] != -1 and $finPos[$#subWt] != -1
!ll&&!rl&&r
13893
MC/DC100%3/3
$iniPos[0] != -1 and $finPos[$#subWt] != -1 and &_eqArray(\@strWt, \@subWt, $lev)
$iniPos[0] != -1 $finPos[$#subWt] != -1 &_eqArray(\@strWt, \@subWt, $lev)
Truth table100%4/4
A and B and C
A= $iniPos[0] != -1B= $finPos[$#subWt] != -1C= &_eqArray(\@strWt, \@subWt, $lev)
ABCresult
0XX0
10X0
1100
1111
941 $finPos[$#subWt] != NOMATCHPOS &&
942 _eqArray(\@strWt, \@subWt, $lev)) {
943 144 my $temp = $iniPos[0] + $pos;
944  
945 144 ▶ if ($glob) {
Branch: 1 branch
BranchTrueFalseTotal
if ($glob) { } 90 54 144
946 90 push @g_ret, [$temp, $finPos[$#subWt] - $iniPos[0]];
947 90 splice @strWt, 0, $#subWt;
948 90 splice @iniPos, 0, $#subWt;
949 90 splice @finPos, 0, $#subWt;
950 }
951 else {
952 return wantarray
953 54 ▶ ? ($temp, $finPos[$#subWt] - $iniPos[0])
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 35 19 54
954 : $temp;
955 }
956 }
957 843 shift @strWt;
958 843 shift @iniPos;
959 843 shift @finPos;
960 }
961 }
962  
963 61 ▶ return $glob
Branch: 2 branches
BranchTrueFalseTotal
$glob ? : 38 23 61
wantarray ? : 15 8 23
964 ? @g_ret
965 : wantarray ? () : NOMATCHPOS;
966 }
967  
968 ##
969 ## scalarref to matching part = match(string, substring)
970 ##
971 sub match
972 35 ▶{
Subroutine match: called CC=3 SCAR=11.0
Pod documented
973 35 my $self = shift;
974 35 ▶ if (my($pos,$len) = $self->index($_[0], $_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self->index($_[0], $_[1])) { } 22 5 27
975 22 my $temp = substr($_[0], $pos, $len);
976 22 ▶ return wantarray ? $temp : \$temp;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 18 4 22
977 # An lvalue ref \substr should be avoided,
978 # since its value is affected by modification of its referent.
979 }
980 else {
981 5 return;
982 }
983 }
984  
985 ##
986 ## arrayref matching parts = gmatch(string, substring)
987 ##
988 sub gmatch
989 6 ▶{
Subroutine gmatch: called CC=1 SCAR=0.0
Pod documented
990 6 my $self = shift;
991 6 my $str = shift;
992 6 my $sub = shift;
993 6 return map substr($str, $_->[0], $_->[1]),
994 $self->index($str, $sub, 0, 'g');
995 }
996  
997 ##
998 ## bool subst'ed = subst(string, substring, replace)
999 ##
1000 sub subst
1001 5 ▶{
Subroutine subst: called CC=4 SCAR=13.9
Pod documented
1002 5 my $self = shift;
1003 5 ▶ my $code = ref $_[2] eq 'CODE' ? $_[2] : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[2] eq 'CODE' ? : 2 3 5
1004  
1005 5 ▶ if (my($pos,$len) = $self->index($_[0], $_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $self->index($_[0], $_[1])) { } 3 2 5
1006 3 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) { } 1 2 3
1007 1 my $mat = substr($_[0], $pos, $len);
1008 1 substr($_[0], $pos, $len, $code->($mat));
1009 } else {
1010 2 substr($_[0], $pos, $len, $_[2]);
1011 }
1012 3 return TRUE;
1013 }
1014 else {
1015 2 return FALSE;
1016 }
1017 }
1018  
1019 ##
1020 ## int count = gsubst(string, substring, replace)
1021 ##
1022 sub gsubst
1023 34 ▶{
Subroutine gsubst: called CC=4 SCAR=13.9
Pod documented
1024 34 my $self = shift;
1025 34 ▶ my $code = ref $_[2] eq 'CODE' ? $_[2] : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[2] eq 'CODE' ? : 29 5 34
1026 34 my $cnt = 0;
1027  
1028 # Replacement is carried out from the end, then use reverse.
1029 34 for my $pos_len (reverse $self->index($_[0], $_[1], 0, 'g')) {
1030 98 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) { } 78 20 98
1031 78 my $mat = substr($_[0], $pos_len->[0], $pos_len->[1]);
1032 78 substr($_[0], $pos_len->[0], $pos_len->[1], $code->($mat));
1033 } else {
1034 20 substr($_[0], $pos_len->[0], $pos_len->[1], $_[2]);
1035 }
1036 98 $cnt++;
1037 }
1038 34 return $cnt;
1039 }
1040  
1041 139 1;
1042 __END__
↑ Summary blib/lib/Unicode/Collate/Locale.pm »