lib/UTF8/R2.pm

filter: Statementstmt 89.3% 369 / 413 Branchbran 86.4% 384 / 444 Conditioncond 57.5% 46 / 80 MC/DCmcdc 32.0% 16 / 50 Subroutinesub 75.0% 33 / 44 Podpod 8.3% 2 / 24 totaltotal 80.5% 850 / 1055 CC 251 SCAR 38.8
CC
251
Cov
85%
qr
108.7
list_all_by_hyphen_utf8_like
47.0
tr
30.2
CRAP 48.2
↑ Summary
1 package UTF8::R2;
2 ######################################################################
3 #
4 # UTF8::R2 - makes UTF-8 scripting easy for enterprise use
5 #
6 # http://search.cpan.org/dist/UTF8-R2/
7 #
8 # Copyright (c) 2019, 2020, 2021, 2022, 2023, 2026 INABA Hitoshi <ina.cpan@gmail.com> in a CPAN
9 ######################################################################
10  
11 70 ▶use 5.00503; # Universal Consensus 1998 for primetools
Subroutine BEGIN: called CC=1 SCAR=0.0
12 # use 5.008001; # Lancaster Consensus 2013 for toolchains
13  
14 70 $VERSION = '0.31';
15 70 $VERSION = $VERSION;
16  
17 70 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 0 ▶BEGIN { if ($] < 5.006 && !defined(&warnings::import)) { $INC{'warnings.pm'} = 'stub'; eval 'package warnings; sub import {}' } } use warnings; local $^W=1;
Subroutine BEGIN: called CC=3 SCAR=13.0
Subroutine BEGIN: called CC=1 SCAR=0.7
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.006" and not defined &warnings::import) 0 70 70
Condition33%1/3
$] < "5.006" and not defined &warnings::import
!ll&&!rl&&r
7000
MC/DC0%0/2
$] < "5.006" and not defined &warnings::import
$] < "5.006" not defined &warnings::import
Truth table33%1/3
A and not(B)
A= $] < "5.006"B= not defined &warnings::import
ABresult
0X0
100
111
19 70 ▶use Symbol ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 70 my %utf8_codepoint = (
22  
23 # beautiful concept in young days, however disabled 5-6 octets for safety
24 # https://www.ietf.org/rfc/rfc2279.txt
25 70 'RFC2279' => qr{(?>@{[join('', qw(
26 [\x00-\x7F\x80-\xBF\xC0-\xC1\xF5-\xFF] |
27 [\xC2-\xDF][\x80-\xBF] |
28 70 [\xE0-\xEF][\x80-\xBF][\x80-\xBF] |
29 [\xF0-\xF4][\x80-\xBF][\x80-\xBF][\x80-\xBF] |
30 [\x00-\xFF]
31 70 ))]})}x,
32  
33 # https://tools.ietf.org/rfc/rfc3629.txt
34 70 'RFC3629' => qr{(?>@{[join('', qw(
35 [\x00-\x7F\x80-\xBF\xC0-\xC1\xF5-\xFF] |
36 [\xC2-\xDF][\x80-\xBF] |
37 70 [\xE0-\xE0][\xA0-\xBF][\x80-\xBF] |
38 [\xE1-\xEC][\x80-\xBF][\x80-\xBF] |
39 [\xED-\xED][\x80-\x9F][\x80-\xBF] |
40 [\xEE-\xEF][\x80-\xBF][\x80-\xBF] |
41 [\xF0-\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF] |
42 [\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF] |
43 [\xF4-\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF] |
44 70 ▶ [\x00-\xFF]
Branch: 1 branch
BranchTrueFalseTotal
$^X =~ /jperl(\.exe)?\z/i && `$^X -v` =~ /SJIS version/ ? : 0 70 70
Condition33%1/3
$^X =~ /jperl(\.exe)?\z/i and `$^X -v` =~ /SJIS version/
!ll&&!rl&&r
7000
MC/DC0%0/2
$^X =~ /jperl(\.exe)?\z/i and `$^X -v` =~ /SJIS version/
$^X =~ /jperl(\.exe)?\z/i `$^X -v` =~ /SJIS version/
Truth table33%1/3
A and B
A= $^X =~ /jperl(\.exe)?\z/iB= `$^X -v` =~ /SJIS version/
ABresult
0X0
100
111
45 ))]})}x,
46  
47 70 # http://simonsapin.github.io/wtf-8/
48 70 'WTF8' => qr{(?>@{[join('', qw(
49 70 [\x00-\x7F\x80-\xBF\xC0-\xC1\xF5-\xFF] |
50 70 [\xC2-\xDF][\x80-\xBF] |
51 70 [\xE0-\xE0][\xA0-\xBF][\x80-\xBF] |
52 70 [\xE1-\xEF][\x80-\xBF][\x80-\xBF] |
53 [\xF0-\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF] |
54 [\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF] |
55 [\xF4-\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF] |
56 69 ▶ [\x00-\xFF]
Subroutine import: called CC=8 SCAR=21.0
57 69 ))]})}x,
58  
59 # optimized RFC3629 for ja_JP
60 69 ▶ 'RFC3629.ja_JP' => qr{(?>@{[join('', qw(
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and $_[0] =~ /\A [0-9] /msx) 0 69 69
Condition66%2/3
defined $_[0] and $_[0] =~ /\A [0-9] /msx
!ll&&!rl&&r
39300
MC/DC0%0/2
defined $_[0] and $_[0] =~ /\A [0-9] /msx
defined $_[0] $_[0] =~ /\A [0-9] /msx
Truth table66%2/3
A and B
A= defined $_[0]B= $_[0] =~ /\A [0-9] /msx
ABresult
0X0
100
111
61 0 ▶ [\x00-\x7F\x80-\xBF\xC0-\xC1\xF5-\xFF] |
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] ne $UTF8::R2::VERSION) 0 0 0
62 0 [\xE1-\xEC][\x80-\xBF][\x80-\xBF] |
63 0 [\xC2-\xDF][\x80-\xBF] |
64 [\xEE-\xEF][\x80-\xBF][\x80-\xBF] |
65 0 [\xF0-\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF] |
66 [\xE0-\xE0][\xA0-\xBF][\x80-\xBF] |
67 [\xED-\xED][\x80-\x9F][\x80-\xBF] |
68 69 [\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF] |
69 [\xF4-\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF] |
70 [\x00-\xFF]
71 30 ▶ ))]})}x,
Branch: 3 branches
BranchTrueFalseTotal
if ($_ eq '*mb') { } 22 8 30
elsif ($_ eq '%mb') { } 5 3 8
elsif (defined $utf8_codepoint{$_}) { } 3 0 3
72 70 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
73 # optimized WTF-8 for ja_JP
74 'WTF8.ja_JP' => qr{(?>@{[join('', qw(
75 22 [\x00-\x7F\x80-\xBF\xC0-\xC1\xF5-\xFF] |
76 22 [\xE1-\xEF][\x80-\xBF][\x80-\xBF] |
77 22 [\xC2-\xDF][\x80-\xBF] |
78 22 [\xE0-\xE0][\xA0-\xBF][\x80-\xBF] |
79 22 [\xF0-\xF0][\x90-\xBF][\x80-\xBF][\x80-\xBF] |
80 22 [\xF1-\xF3][\x80-\xBF][\x80-\xBF][\x80-\xBF] |
81 22 [\xF4-\xF4][\x80-\x8F][\x80-\xBF][\x80-\xBF] |
82 22 [\x00-\xFF]
83 22 ))]})}x,
84 22 );
85 22  
86 22 # supports /./
87 22 my $x =
88 22 ($^X =~ /jperl(\.exe)?\z/i) && (`$^X -v` =~ /SJIS version/) ?
89 22 q{(?>[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]|[\x00-\xFF])} : # debug tool using JPerl(SJIS version)
90 22 $utf8_codepoint{'RFC3629'};
91 22  
92 22 # supports [\b] \d \h \s \v \w
93 22 my $bare_backspace = '\x08';
94 22 my $bare_d = '0123456789';
95 my $bare_h = '\x09\x20';
96 my $bare_s = '\t\n\f\r\x20';
97 my $bare_v = '\x0A\x0B\x0C\x0D';
98 my $bare_w = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
99 70 ▶ 
Subroutine BEGIN: called CC=1 SCAR=0.0
100 #---------------------------------------------------------------------
101 # exports mb package
102 5 sub import {
103 5 my $self = shift @_;
104  
105 # confirm version
106 if (defined($_[0]) and ($_[0] =~ /\A [0-9] /xms)) {
107 if ($_[0] ne $UTF8::R2::VERSION) {
108 3 my($package, $filename, $line) = caller;
109 die "$filename requires @{[__PACKAGE__]} $_[0], however @{[__FILE__]} am only $UTF8::R2::VERSION, stopped at $filename line $line.\n";
110 }
111 shift @_;
112 }
113 69  
114 69 for (@_) {
115  
116 # export *mb
117 69 if ($_ eq '*mb') {
118 69 no strict qw(refs);
119  
120 # tie my %mb, __PACKAGE__; # makes: Parentheses missing around "my" list
121 tie my %mb, 'UTF8::R2';
122 *{caller().'::mb'} = \%mb;
123 0 ▶ *{caller().'::mb::ORIG_PROGRAM_NAME'} = \$UTF8::R2::ORIG_PROGRAM_NAME;
Subroutine confess: not called CC=2 SCAR=17.9
Pod undocumented
124 0 *{caller().'::mb::PERL'} = \$UTF8::R2::PERL;
125 0 *{caller().'::mb::chop'} = \&UTF8::R2::chop;
126 0 ▶ *{caller().'::mb::chr'} = \&UTF8::R2::chr;
Branch: 1 branch
BranchTrueFalseTotal
if (() = caller $i) 0 0 0
127 0 *{caller().'::mb::do'} = \&UTF8::R2::do;
128 0 *{caller().'::mb::eval'} = \&UTF8::R2::eval;
129 *{caller().'::mb::getc'} = \&UTF8::R2::getc;
130 0 *{caller().'::mb::index'} = \&UTF8::R2::index;
131 0 *{caller().'::mb::index_byte'} = \&UTF8::R2::index_byte;
132 0 *{caller().'::mb::length'} = \&UTF8::R2::length;
133 *{caller().'::mb::ord'} = \&UTF8::R2::ord;
134 *{caller().'::mb::require'} = \&UTF8::R2::require;
135 *{caller().'::mb::reverse'} = \&UTF8::R2::reverse;
136 *{caller().'::mb::rindex'} = \&UTF8::R2::rindex;
137 36 ▶ *{caller().'::mb::rindex_byte'} = \&UTF8::R2::rindex_byte;
Subroutine chop: called CC=4 SCAR=13.9
Pod undocumented
138 36 *{caller().'::mb::split'} = \&UTF8::R2::split;
139 36 ▶ *{caller().'::mb::substr'} = \&UTF8::R2::substr;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 24 12 36
140 52 ▶ *{caller().'::mb::tr'} = \&UTF8::R2::tr;
Branch: 1 branch
BranchTrueFalseTotal
if (my(@x) = /\G$x/g) 40 12 52
141 40 }
142 40  
143 # export %mb
144 elsif ($_ eq '%mb') {
145 36 no strict qw(refs);
146  
147 # tie my %mb, __PACKAGE__; # makes: Parentheses missing around "my" list
148 tie my %mb, 'UTF8::R2';
149 *{caller().'::mb'} = \%mb;
150 88 ▶ }
Subroutine chr: called CC=3 SCAR=11.0
Pod undocumented
151 88 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 80 8 88
152 # set script encoding
153 elsif (defined $utf8_codepoint{$_}) {
154 $x = $utf8_codepoint{$_};
155 }
156 }
157 88  
158 88 ▶ # $^X($EXECUTABLE_NAME) for execute MBCS Perl script
Branch: 1 branch
BranchTrueFalseTotal
$number > 0 and do { do { unshift @octet, $number % 256; $number = int $number / 256 } } 80 88 168
159 168 $UTF8::R2::PERL = $^X;
160 168 $UTF8::R2::PERL = $UTF8::R2::PERL; # to avoid: Name "UTF8::R2::PERL" used only once: possible typo at ...
161  
162 88 # original $0($PROGRAM_NAME)
163 $UTF8::R2::ORIG_PROGRAM_NAME = $0;
164 $UTF8::R2::ORIG_PROGRAM_NAME = $UTF8::R2::ORIG_PROGRAM_NAME; # to avoid: Name "UTF8::R2::ORIG_PROGRAM_NAME" used only once: possible typo at ...
165 }
166  
167 10 ▶#---------------------------------------------------------------------
Subroutine do: called CC=1 SCAR=0.0
Pod undocumented
168 # confess() for this module
169 sub confess {
170 10 my $i = 0;
171 my @confess = ();
172 while (my($package, $filename, $line, $subroutine) = caller($i)) {
173 push @confess, "[$i] $filename($line) $subroutine\n";
174 $i++;
175 }
176 print STDERR "\n", @_, "\n";
177 print STDERR CORE::reverse @confess;
178 die;
179 2 ▶}
Subroutine eval: called CC=2 SCAR=7.2
Pod undocumented
180 2 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 0 2
181 #---------------------------------------------------------------------
182 # chop() for UTF-8 codepoint string
183 2 sub UTF8::R2::chop (@) {
184 my $chop = '';
185 for (@_ ? @_ : $_) {
186 if (my @x = /\G$x/g) {
187 $chop = pop @x;
188 $_ = join '', @x;
189 }
190 }
191 return $chop;
192 28 ▶}
Subroutine getc: called CC=6 SCAR=17.9
Pod undocumented
193 28 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 8 20 28
194 28 #---------------------------------------------------------------------
195 28 ▶# chr() for UTF-8 codepoint string
Branch: 4 branches
BranchTrueFalseTotal
if ($getc =~ /\A [\x00-\x7F\x80-\xC1\xF5-\xFF] \z/msx) { } 10 18 28
elsif ($getc =~ /\A [\xC2-\xDF] \z/msx) { } 8 10 18
elsif ($getc =~ /\A [\xE0-\xEF] \z/msx) { } 6 4 10
elsif ($getc =~ /\A [\xF0-\xF4] \z/msx) { } 4 0 4
196 sub UTF8::R2::chr (;$) {
197 my $number = @_ ? $_[0] : $_;
198 8  
199 # Negative values give the Unicode replacement character (chr(0xfffd)),
200 # except under the bytes pragma, where the low eight bits of the value
201 6 # (truncated to an integer) are used.
202 6  
203 my @octet = ();
204 CORE::do {
205 4 unshift @octet, ($number % 0x100);
206 4 $number = int($number / 0x100);
207 4 } while ($number > 0);
208 return pack 'C*', @octet;
209 28 }
210  
211 #---------------------------------------------------------------------
212 # mb::do() like do(), mb.pm compatible
213 sub UTF8::R2::do ($) {
214 16 ▶ 
Subroutine index: called CC=3 SCAR=11.0
Pod undocumented
215 16 # run as Perl script
216 16 ▶ return CORE::eval sprintf(<<'END', (caller)[0, 2, 1]);
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) { } 8 8 16
217 8 package %s;
218 #line %s "%s"
219 CORE::do "$_[0]";
220 8 END
221 }
222 16 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if ($index == -1) { } 8 8 16
223 8 #---------------------------------------------------------------------
224 # mb::eval() like eval(), mb.pm compatible
225 sub UTF8::R2::eval (;$) {
226 8 local $_ = @_ ? $_[0] : $_;
227  
228 # run as Perl script in caller package
229 return CORE::eval sprintf(<<'END', (caller)[0, 2, 1], $_);
230 package %s;
231 #line %s "%s"
232 16 ▶%s
Subroutine index_byte: called CC=2 SCAR=6.9
Pod undocumented
233 16 ▶END
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) { } 8 8 16
234 8 }
235  
236 #---------------------------------------------------------------------
237 8 # getc() for UTF-8 codepoint string
238 sub UTF8::R2::getc (;*) {
239 my $fh = @_ ? Symbol::qualify_to_ref($_[0], caller()) : \*STDIN;
240 my $getc = CORE::getc $fh;
241 if ($getc =~ /\A [\x00-\x7F\x80-\xC1\xF5-\xFF] \z/xms) {
242 }
243 6 ▶ elsif ($getc =~ /\A [\xC2-\xDF] \z/xms) {
Subroutine lc: called CC=3 SCAR=11.0
Pod undocumented
244 6 ▶ $getc .= CORE::getc $fh;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 5 1 6
245 }
246 6 ▶ elsif ($getc =~ /\A [\xE0-\xEF] \z/xms) {
Condition66%2/3
{'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'}->{$_} || $_
l!l&&r!l&&!r
56530
MC/DC0%0/2
{'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'}->{$_} || $_
{'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'}->{$_} $_
Truth table66%2/3
A || B
A= {'A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z'}->{$_}B= $_
ABresult
1X1
011
000
247 $getc .= CORE::getc $fh;
248 $getc .= CORE::getc $fh;
249 }
250 elsif ($getc =~ /\A [\xF0-\xF4] \z/xms) {
251 $getc .= CORE::getc $fh;
252 2 ▶ $getc .= CORE::getc $fh;
Subroutine lcfirst: called CC=3 SCAR=11.4
Pod undocumented
253 2 ▶ $getc .= CORE::getc $fh;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 1 2
254 2 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if (/\A($x)(.*)\z/s) { } 2 0 2
255 2 return $getc;
256 }
257  
258 0 #---------------------------------------------------------------------
259 # index() for UTF-8 codepoint string
260 sub UTF8::R2::index ($$;$) {
261 my $index = 0;
262 if (@_ == 3) {
263 $index = CORE::index $_[0], $_[1], CORE::length(UTF8::R2::substr($_[0], 0, $_[2]));
264 32 ▶ }
Subroutine length: called CC=2 SCAR=6.9
Pod undocumented
265 32 ▶ else {
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 24 8 32
266 32 $index = CORE::index $_[0], $_[1];
267 }
268 if ($index == -1) {
269 return -1;
270 }
271 30 ▶ else {
Subroutine ord: called CC=4 SCAR=13.9
Pod undocumented
272 30 ▶ return UTF8::R2::length(CORE::substr $_[0], 0, $index);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 15 15 30
273 30 }
274 30 ▶}
Branch: 1 branch
BranchTrueFalseTotal
if (/\A($x)/) 30 0 30
275 30  
276 70 #---------------------------------------------------------------------
277 # JPerl like index() for UTF-8 codepoint string
278 sub UTF8::R2::index_byte ($$;$) {
279 30 if (@_ == 3) {
280 return CORE::index $_[0], $_[1], CORE::length(UTF8::R2::substr($_[0], 0, $_[2]));
281 }
282 else {
283 return CORE::index $_[0], $_[1];
284 200526 ▶ }
Subroutine list_all_by_hyphen_utf8_like: called CC=46 SCAR=38.5
Pod undocumented
285 200526 }
286 200526  
287 200526 #---------------------------------------------------------------------
288 # universal lc() for UTF-8 codepoint string
289 200526 ▶sub UTF8::R2::lc (;$) {
Branch: 4 branches
BranchTrueFalseTotal
if (do { CORE::length $a == 1 }) { } 11414 189112 200526
elsif (CORE::length $a == 2) { } 22058 167054 189112
elsif (CORE::length $a == 3) { } 107566 59488 167054
elsif (CORE::length $a == 4) { } 59488 0 59488
290 local $_ = @_ ? $_[0] : $_;
291 11414 ▶ # A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z
Branch: 4 branches
BranchTrueFalseTotal
if (do { CORE::length $b == 1 }) { } 374 11040 11414
elsif (CORE::length $b == 2) { } 960 10080 11040
elsif (CORE::length $b == 3) { } 5088 4992 10080
elsif (CORE::length $b == 4) { } 4992 0 4992
292 return join '', map { {qw( A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z )}->{$_}||$_ } /\G$x/g;
293 # A a B b C c D d E e F f G g H h I i J j K k L l M m N n O o P p Q q R r S s T t U u V v W w X x Y y Z z
294 374 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$a[1] <= $b[1] ? : 374 0 374
295  
296 #---------------------------------------------------------------------
297 # universal lcfirst() for UTF-8 codepoint string
298 sub UTF8::R2::lcfirst (;$) {
299 local $_ = @_ ? $_[0] : $_;
300 960 ▶ if (/\A($x)(.*)\z/s) {
Branch: 1 branch
BranchTrueFalseTotal
194 < $b[1] ? : 476 484 960
301 return UTF8::R2::lc($1) . $2;
302 }
303 else {
304 return '';
305 }
306 }
307 5088 ▶ 
Branch: 2 branches
BranchTrueFalseTotal
128 < $b[2] ? : 2988 2100 5088
224 < $b[1] ? : 4160 928 5088
308 #---------------------------------------------------------------------
309 # length() for UTF-8 codepoint string
310 sub UTF8::R2::length (;$) {
311 local $_ = @_ ? $_[0] : $_;
312 return scalar(() = /\G$x/g);
313 }
314  
315 #---------------------------------------------------------------------
316 4992 ▶# ord() for UTF-8 codepoint string
Branch: 3 branches
BranchTrueFalseTotal
128 < $b[3] ? : 2464 2528 4992
128 < $b[2] ? : 3168 1824 4992
240 < $b[1] ? : 3552 1440 4992
317 sub UTF8::R2::ord (;$) {
318 local $_ = @_ ? $_[0] : $_;
319 my $ord = 0;
320 if (/\A($x)/) {
321 for my $octet (unpack 'C*', $1) {
322 $ord = $ord * 0x100 + $octet;
323 }
324 }
325 return $ord;
326 }
327 22058 ▶ 
Branch: 3 branches
BranchTrueFalseTotal
if (do { CORE::length $b == 2 }) { } 1226 20832 22058
elsif (CORE::length $b == 3) { } 10464 10368 20832
elsif (CORE::length $b == 4) { } 10368 0 10368
328 #---------------------------------------------------------------------
329 1226 ▶# qr/ [A-Z] / for UTF-8 codepoint string
Branch: 1 branch
BranchTrueFalseTotal
$a[1] < 223 ? : 858 368 1226
330 sub list_all_by_hyphen_utf8_like {
331 my($a, $b) = @_;
332 my @a = (undef, unpack 'C*', $a);
333 1226 ▶ my @b = (undef, unpack 'C*', $b);
Branch: 1 branch
BranchTrueFalseTotal
194 < $b[1] ? : 858 368 1226
334  
335 if (0) { }
336 elsif (CORE::length($a) == 1) {
337 1226 if (0) { }
338 elsif (CORE::length($b) == 1) {
339 return (
340 $a[1]<=$b[1] ? sprintf(join('', qw( [\x%02x-\x%02x] )), $a[1],
341 10464 ▶ $b[1]) : (),
Branch: 3 branches
BranchTrueFalseTotal
128 < $b[2] ? : 6144 4320 10464
224 < $b[1] ? : 8560 1904 10464
$a[1] < 223 ? : 5184 5280 10464
342 );
343 }
344 elsif (CORE::length($b) == 2) {
345 return (
346 sprintf(join('', qw( \x%02x [\x80-\x%02x] )), $b[1], $b[2]),
347 0xC2 < $b[1] ? sprintf(join('', qw( [\xC2-\x%02x] [\x80-\xBF ] )), $b[1]-1 ) : (),
348 sprintf(join('', qw( [\x%02x-\x7F] )), $a[1] ),
349 );
350 10368 ▶ }
Branch: 4 branches
BranchTrueFalseTotal
128 < $b[3] ? : 5120 5248 10368
128 < $b[2] ? : 6576 3792 10368
240 < $b[1] ? : 7392 2976 10368
$a[1] < 223 ? : 5120 5248 10368
351 elsif (CORE::length($b) == 3) {
352 return (
353 sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3]),
354 0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
355 0xE0 < $b[1] ? sprintf(join('', qw( [\xE0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
356 sprintf(join('', qw( [\xC2-\xDF ] [\x80-\xBF ] )), ),
357 sprintf(join('', qw( [\x%02x-\x7F] )), $a[1] ),
358 );
359 }
360 elsif (CORE::length($b) == 4) {
361 107566 ▶ return (
Branch: 2 branches
BranchTrueFalseTotal
if (do { CORE::length $b == 3 }) { } 34606 72960 107566
elsif (CORE::length $b == 4) { } 72960 0 72960
362 sprintf(join('', qw( \x%02x \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3], $b[4]),
363 34606 ▶0x80 < $b[3] ? sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2], $b[3]-1 ) : (),
Branch: 2 branches
BranchTrueFalseTotal
$a[1] < 239 ? : 33386 1220 34606
$a[2] < 191 ? : 20894 13712 34606
364 0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
365 0xF0 < $b[1] ? sprintf(join('', qw( [\xF0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
366 sprintf(join('', qw( [\xE0-\xEF ] [\x80-\xBF ] [\x80-\xBF ] )), ),
367 sprintf(join('', qw( [\xC2-\xDF ] [\x80-\xBF ] )), ),
368 34606 ▶ sprintf(join('', qw( [\x%02x-\x7F] )), $a[1] ),
Branch: 2 branches
BranchTrueFalseTotal
128 < $b[2] ? : 19006 15600 34606
224 < $b[1] ? : 33380 1226 34606
369 );
370 }
371 }
372 elsif (CORE::length($a) == 2) {
373 34606 if (0) { }
374 elsif (CORE::length($b) == 2) {
375 my $lower_limit = join('|',
376 $a[1] < 0xDF ? sprintf(join('', qw( [\x%02x-\xDF] [\x80-\xBF ] )), $a[1]+1 ) : (),
377 72960 ▶ sprintf(join('', qw( \x%02x [\x%02x-\xBF] )), $a[1], $a[2]),
Branch: 5 branches
BranchTrueFalseTotal
128 < $b[3] ? : 36096 36864 72960
128 < $b[2] ? : 46176 26784 72960
240 < $b[1] ? : 52416 20544 72960
$a[1] < 239 ? : 59520 13440 72960
$a[2] < 191 ? : 42368 30592 72960
378 );
379 my $upper_limit = join('|',
380 sprintf(join('', qw( \x%02x [\x80-\x%02x] )), $b[1], $b[2]),
381 0xC2 < $b[1] ? sprintf(join('', qw( [\xC2-\x%02x] [\x80-\xBF ] )), $b[1]-1 ) : (),
382 );
383 return qq{(?=$lower_limit)(?=$upper_limit)};
384 }
385 elsif (CORE::length($b) == 3) {
386 return (
387 sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3] ),
388 59488 ▶0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
Branch: 1 branch
BranchTrueFalseTotal
if (do { CORE::length $b == 4 }) 59488 0 59488
389 0 0xE0 < $b[1] ? sprintf(join('', qw( [\xE0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
390 59488 ▶$a[1] < 0xDF ? sprintf(join('', qw( [\x%02x-\xDF] [\x80-\xBF ] )), $a[1]+1 ) : (),
Branch: 3 branches
BranchTrueFalseTotal
$a[1] < 244 ? : 55144 4344 59488
$a[2] < 191 ? : 34388 25100 59488
$a[3] < 191 ? : 31456 28032 59488
391 sprintf(join('', qw( \x%02x [\x%02x-\xBF] )), $a[1], $a[2] ),
392 );
393 }
394 elsif (CORE::length($b) == 4) {
395 return (
396 59488 ▶ sprintf(join('', qw( \x%02x \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3], $b[4]),
Branch: 3 branches
BranchTrueFalseTotal
128 < $b[3] ? : 31456 28032 59488
128 < $b[2] ? : 34388 25100 59488
240 < $b[1] ? : 55144 4344 59488
397 0x80 < $b[3] ? sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2], $b[3]-1 ) : (),
398 0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
399 0xF0 < $b[1] ? sprintf(join('', qw( [\xF0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
400 sprintf(join('', qw( [\xE0-\xEF ] [\x80-\xBF ] [\x80-\xBF ] )), ),
401 $a[1] < 0xDF ? sprintf(join('', qw( [\x%02x-\xDF] [\x80-\xBF ] )), $a[1]+1 ) : (),
402 59488 sprintf(join('', qw( \x%02x [\x%02x-\xBF] )), $a[1], $a[2] ),
403 );
404 }
405 }
406 elsif (CORE::length($a) == 3) {
407 0 if (0) { }
408 elsif (CORE::length($b) == 3) {
409 my $lower_limit = join('|',
410 $a[1] < 0xEF ? sprintf(join('', qw( [\x%02x-\xEF] [\x80-\xBF ] [\x80-\xBF ] )), $a[1]+1 ) : (),
411 $a[2] < 0xBF ? sprintf(join('', qw( \x%02x [\x%02x-\xBF] [\x80-\xBF ] )), $a[1], $a[2]+1 ) : (),
412 209731 ▶ sprintf(join('', qw( \x%02x \x%02x [\x%02x-\xBF] )), $a[1], $a[2], $a[3]),
Subroutine qr: called CC=92 SCAR=46.9
Pod undocumented
413 );
414 209731 my $upper_limit = join('|',
415 209731 ▶ sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3]),
Branch: 1 branch
BranchTrueFalseTotal
if (($modifiers) = $_[0] =~ /\A \( \? \^? (.*?) : /x) 209731 0 209731
416 209731 0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
417 0xE0 < $b[1] ? sprintf(join('', qw( [\xE0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
418 );
419 209731 return qq{(?=$lower_limit)(?=$upper_limit)};
420 209731 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ s/ \A ( (?> \[ (?: \[:[^:]+?:\] | \\x\{[0123456789ABCDEFabcdef]+\} | \\c[\x00-\xFF] | (?>\\$x) | $x )+? \] ) | \\x\{[0123456789ABCDEFabcdef]+\} | \\c[\x00-\xFF] | (?>\\$x) | $x ) //x) 1261613 209731 1471344
421 elsif (CORE::length($b) == 4) {
422 return (
423 sprintf(join('', qw( \x%02x \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3], $b[4]),
424 1261613 0x80 < $b[3] ? sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2], $b[3]-1 ) : (),
425 0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
426 0xF0 < $b[1] ? sprintf(join('', qw( [\xF0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
427 1261613 ▶$a[1] < 0xEF ? sprintf(join('', qw( [\x%02x-\xEF] [\x80-\xBF ] [\x80-\xBF ] )), $a[1]+1 ) : (),
Branch: 18 branches
BranchTrueFalseTotal
if (() = $before =~ /\A \[ (\^?) ((?>\\$x|$x)+?) \] \z/x) { } 208402 1053211 1261613
elsif ($before eq '.') { } 498 1052713 1053211
elsif ($before eq '\\B') { } 18 1052695 1052713
elsif ($before eq '\\D') { } 33 1052662 1052695
elsif ($before eq '\\H') { } 24 1052638 1052662
elsif ($before eq '\\N') { } 18 1052620 1052638
elsif ($before eq '\\R') { } 39 1052581 1052620
elsif ($before eq '\\S') { } 24 1052557 1052581
elsif ($before eq '\\V') { } 24 1052533 1052557
elsif ($before eq '\\W') { } 192 1052341 1052533
elsif ($before eq '\\b') { } 18 1052323 1052341
elsif ($before eq '\\d') { } 33 1052290 1052323
elsif ($before eq '\\h') { } 24 1052266 1052290
elsif ($before eq '\\s') { } 24 1052242 1052266
elsif ($before eq '\\v') { } 24 1052218 1052242
elsif ($before eq '\\w') { } 192 1052026 1052218
elsif ($before =~ /\A[?+*{]\z/) { } 210172 841854 1052026
elsif ($before =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x) { } 18 841836 841854
428 208402 $a[2] < 0xBF ? sprintf(join('', qw( \x%02x [\x%02x-\xBF] [\x80-\xBF ] )), $a[1], $a[2]+1 ) : (),
429 208402 sprintf(join('', qw( \x%02x \x%02x [\x%02x-\xBF] )), $a[1], $a[2], $a[3] ),
430 208402 );
431 }
432 208402 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#classmate) 208450 208402 416852
433 208450 elsif (CORE::length($a) == 4) {
434 if (0) { }
435 elsif (CORE::length($b) == 4) {
436 208450 ▶ my $lower_limit = join('|',
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#classmate and $classmate[$i + 1] eq '-') { } 200526 7924 208450
Condition100%3/3
$i < $#classmate and $classmate[$i + 1] eq "-"
!ll&&!rl&&r
787648200526
MC/DC100%2/2
$i < $#classmate and $classmate[$i + 1] eq "-"
$i < $#classmate $classmate[$i + 1] eq "-"
Truth table100%3/3
A and B
A= $i < $#classmateB= $classmate[$i + 1] eq "-"
ABresult
0X0
100
111
437 200526 ▶$a[1] < 0xF4 ? sprintf(join('', qw( [\x%02x-\xF4] [\x80-\xBF ] [\x80-\xBF ] [\x80-\xBF ] )), $a[1]+1 ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$classmate[$i + 0] =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x ? : 18 200508 200526
438 200526 ▶$a[2] < 0xBF ? sprintf(join('', qw( \x%02x [\x%02x-\xBF] [\x80-\xBF ] [\x80-\xBF ] )), $a[1], $a[2]+1 ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$classmate[$i + 2] =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x ? : 18 200508 200526
439 200526 $a[3] < 0xBF ? sprintf(join('', qw( \x%02x \x%02x [\x%02x-\xBF] [\x80-\xBF ] )), $a[1], $a[2], $a[3]+1 ) : (),
440 200526 sprintf(join('', qw( \x%02x \x%02x \x%02x [\x%02x-\xBF] )), $a[1], $a[2], $a[3], $a[4]),
441 );
442 my $upper_limit = join('|',
443 sprintf(join('', qw( \x%02x \x%02x \x%02x [\x80-\x%02x] )), $b[1], $b[2], $b[3], $b[4]),
444 0x80 < $b[3] ? sprintf(join('', qw( \x%02x \x%02x [\x80-\x%02x] [\x80-\xBF ] )), $b[1], $b[2], $b[3]-1 ) : (),
445 0x80 < $b[2] ? sprintf(join('', qw( \x%02x [\x80-\x%02x] [\x80-\xBF ] [\x80-\xBF ] )), $b[1], $b[2]-1 ) : (),
446 0xF0 < $b[1] ? sprintf(join('', qw( [\xF0-\x%02x] [\x80-\xBF ] [\x80-\xBF ] [\x80-\xBF ] )), $b[1]-1 ) : (),
447 7924 ▶ );
Branch: 41 branches
BranchTrueFalseTotal
if ($classmate =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x) { } 18 7906 7924
elsif ($classmate eq '\\D') { } 33 7873 7906
elsif ($classmate eq '\\H') { } 24 7849 7873
elsif ($classmate eq '\\S') { } 24 7825 7849
elsif ($classmate eq '\\V') { } 24 7801 7825
elsif ($classmate eq '\\W') { } 192 7609 7801
elsif ($classmate eq '\\b') { } 3 7606 7609
elsif ($classmate eq '\\d') { } 33 7573 7606
elsif ($classmate eq '\\h') { } 24 7549 7573
elsif ($classmate eq '\\s') { } 24 7525 7549
elsif ($classmate eq '\\v') { } 24 7501 7525
elsif ($classmate eq '\\w') { } 192 7309 7501
elsif ($classmate eq '[:alnum:]') { } 256 7053 7309
elsif ($classmate eq '[:alpha:]') { } 256 6797 7053
elsif ($classmate eq '[:ascii:]') { } 256 6541 6797
elsif ($classmate eq '[:blank:]') { } 256 6285 6541
elsif ($classmate eq '[:cntrl:]') { } 256 6029 6285
elsif ($classmate eq '[:digit:]') { } 256 5773 6029
elsif ($classmate eq '[:graph:]') { } 256 5517 5773
elsif ($classmate eq '[:lower:]') { } 256 5261 5517
elsif ($classmate eq '[:print:]') { } 256 5005 5261
elsif ($classmate eq '[:punct:]') { } 256 4749 5005
elsif ($classmate eq '[:space:]') { } 256 4493 4749
elsif ($classmate eq '[:upper:]') { } 256 4237 4493
elsif ($classmate eq '[:word:]') { } 256 3981 4237
elsif ($classmate eq '[:xdigit:]') { } 256 3725 3981
elsif ($classmate eq '[:^alnum:]') { } 256 3469 3725
elsif ($classmate eq '[:^alpha:]') { } 256 3213 3469
elsif ($classmate eq '[:^ascii:]') { } 256 2957 3213
elsif ($classmate eq '[:^blank:]') { } 256 2701 2957
elsif ($classmate eq '[:^cntrl:]') { } 256 2445 2701
elsif ($classmate eq '[:^digit:]') { } 256 2189 2445
elsif ($classmate eq '[:^graph:]') { } 256 1933 2189
elsif ($classmate eq '[:^lower:]') { } 256 1677 1933
elsif ($classmate eq '[:^print:]') { } 256 1421 1677
elsif ($classmate eq '[:^punct:]') { } 256 1165 1421
elsif ($classmate eq '[:^space:]') { } 256 909 1165
elsif ($classmate eq '[:^upper:]') { } 256 653 909
elsif ($classmate eq '[:^word:]') { } 256 397 653
elsif ($classmate eq '[:^xdigit:]') { } 256 141 397
elsif (CORE::length $classmate == 1) { } 21 120 141
448 18 return qq{(?=$lower_limit)(?=$upper_limit)};
449 }
450 }
451  
452 33 # over range of codepoint
453 24 confess sprintf(qq{@{[__FILE__]}: codepoint class [$_[0]-$_[1]] is not 1 to 4 octets (%d-%d)}, CORE::length($a), CORE::length($b));
454 }
455  
456 24 #---------------------------------------------------------------------
457 24 # qr// for UTF-8 codepoint string
458 192 sub UTF8::R2::qr ($) {
459 3  
460 33 my $modifiers = '';
461 24 if (($modifiers) = $_[0] =~ /\A \( \? \^? (.*?) : /x) {
462 24 $modifiers =~ s/-.*//;
463 24 }
464 192  
465 my @after = ();
466 while ($_[0] =~ s! \A (
467 256 (?> \[ (?: \[:[^:]+?:\] | \\x\{[0123456789ABCDEFabcdef]+\} | \\c[\x00-\xFF] | (?>\\$x) | $x )+? \] ) |
468 256 \\x\{[0123456789ABCDEFabcdef]+\} | \\c[\x00-\xFF] | (?>\\$x) | $x
469 256 ) !!x) {
470 256 my $before = $1;
471 256  
472 256 # [^...] or [...]
473 256 if (my($negative, $class) = $before =~ /\A \[ (\^?) ((?>\\$x|$x)+?) \] \z/x) {
474 256 my @classmate = $class =~ /\G (?: \[:.+?:\] | \\x\{[0123456789ABCDEFabcdef]+\} | (?>\\$x) | $x ) /xg;
475 256 my @sbcs = ();
476 256 my @xbcs = ();
477 256  
478 256 for (my $i=0; $i <= $#classmate; ) {
479 256 my $classmate = $classmate[$i];
480 256  
481 # hyphen of [A-Z] or [^A-Z]
482 if (($i < $#classmate) and ($classmate[$i+1] eq '-')) {
483 256 my $a = ($classmate[$i+0] =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x) ? UTF8::R2::chr(hex $1) : $classmate[$i+0];
484 256 my $b = ($classmate[$i+2] =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x) ? UTF8::R2::chr(hex $1) : $classmate[$i+2];
485 256 push @xbcs, list_all_by_hyphen_utf8_like($a, $b);
486 256 $i += 3;
487 256 }
488 256  
489 256 # any "one"
490 256 else {
491 256  
492 256 # \x{UTF8hex}
493 256 if ($classmate =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x) {
494 256 push @xbcs, UTF8::R2::chr(hex $1);
495 256 }
496 256  
497 # \any
498 elsif ($classmate eq '\D' ) { push @xbcs, "(?:(?![$bare_d])$x)" }
499 21 elsif ($classmate eq '\H' ) { push @xbcs, "(?:(?![$bare_h])$x)" }
500 120 # elsif ($classmate eq '\N' ) { push @xbcs, "(?:(?!\\n)$x)" } # \N in a character class must be a named character: \N{...} in regex
501 7924 # elsif ($classmate eq '\R' ) { push @xbcs, "(?>\\r\\n|[$bare_v])" } # Unrecognized escape \R in character class passed through in regex
502 elsif ($classmate eq '\S' ) { push @xbcs, "(?:(?![$bare_s])$x)" }
503 elsif ($classmate eq '\V' ) { push @xbcs, "(?:(?![$bare_v])$x)" }
504 elsif ($classmate eq '\W' ) { push @xbcs, "(?:(?![$bare_w])$x)" }
505 elsif ($classmate eq '\b' ) { push @sbcs, $bare_backspace }
506 208402 ▶ elsif ($classmate eq '\d' ) { push @sbcs, $bare_d }
Branch: 2 branches
BranchTrueFalseTotal
if ($negative eq '^') { } 79449 128953 208402
elsif ($] =~ /\A5\.006/) { } 0 128953 128953
507 79449 ▶ elsif ($classmate eq '\h' ) { push @sbcs, $bare_h }
Branch: 3 branches
BranchTrueFalseTotal
@sbcs && @xbcs ? : 0 79449 79449
!@sbcs && @xbcs ? : 79449 0 79449
@sbcs && !@xbcs ? : 0 0 0
Condition22%2/9
@sbcs and @xbcs
!ll&&!rl&&r
7944900
not @sbcs and @xbcs
!ll&&!rl&&r
0079449
@sbcs and not @xbcs
!ll&&!rl&&r
000
MC/DC0%0/2
@sbcs and @xbcs
@sbcs @xbcs
MC/DC0%0/2
not @sbcs and @xbcs
not @sbcs @xbcs
MC/DC0%0/2
@sbcs and not @xbcs
@sbcs not @xbcs
Truth table33%1/3
A and B
A= @sbcsB= @xbcs
ABresult
0X0
100
111
Truth table33%1/3
not(A) and B
A= not @sbcsB= @xbcs
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= @sbcsB= not @xbcs
ABresult
0X0
100
111
508 elsif ($classmate eq '\s' ) { push @sbcs, $bare_s }
509 elsif ($classmate eq '\v' ) { push @sbcs, $bare_v }
510 elsif ($classmate eq '\w' ) { push @sbcs, $bare_w }
511  
512 # [:POSIX:]
513 elsif ($classmate eq '[:alnum:]' ) { push @sbcs, '\x30-\x39\x41-\x5A\x61-\x7A'; }
514 elsif ($classmate eq '[:alpha:]' ) { push @sbcs, '\x41-\x5A\x61-\x7A'; }
515 elsif ($classmate eq '[:ascii:]' ) { push @sbcs, '\x00-\x7F'; }
516 0 ▶ elsif ($classmate eq '[:blank:]' ) { push @sbcs, '\x09\x20'; }
Branch: 3 branches
BranchTrueFalseTotal
@sbcs && @xbcs ? : 0 0 0
!@sbcs && @xbcs ? : 0 0 0
@sbcs && !@xbcs ? : 0 0 0
Condition0%0/9
@sbcs and @xbcs
!ll&&!rl&&r
000
not @sbcs and @xbcs
!ll&&!rl&&r
000
@sbcs and not @xbcs
!ll&&!rl&&r
000
MC/DC0%0/2
@sbcs and @xbcs
@sbcs @xbcs
MC/DC0%0/2
not @sbcs and @xbcs
not @sbcs @xbcs
MC/DC0%0/2
@sbcs and not @xbcs
@sbcs not @xbcs
Truth table0%0/3
A and B
A= @sbcsB= @xbcs
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not @sbcsB= @xbcs
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= @sbcsB= not @xbcs
ABresult
0X0
100
111
517 elsif ($classmate eq '[:cntrl:]' ) { push @sbcs, '\x00-\x1F\x7F'; }
518 elsif ($classmate eq '[:digit:]' ) { push @sbcs, '\x30-\x39'; }
519 elsif ($classmate eq '[:graph:]' ) { push @sbcs, '\x21-\x7F'; }
520 elsif ($classmate eq '[:lower:]' ) { push @sbcs, '\x61-\x7A'; } # /i modifier requires 'a' to 'z' literally
521 elsif ($classmate eq '[:print:]' ) { push @sbcs, '\x20-\x7F'; }
522 elsif ($classmate eq '[:punct:]' ) { push @sbcs, '\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E'; }
523 elsif ($classmate eq '[:space:]' ) { push @sbcs, '\s\x0B'; } # "\s" and vertical tab ("\cK")
524 elsif ($classmate eq '[:upper:]' ) { push @sbcs, '\x41-\x5A'; } # /i modifier requires 'A' to 'Z' literally
525 128953 ▶ elsif ($classmate eq '[:word:]' ) { push @sbcs, '\x30-\x39\x41-\x5A\x5F\x61-\x7A'; }
Branch: 3 branches
BranchTrueFalseTotal
@sbcs && @xbcs ? : 0 128953 128953
!@sbcs && @xbcs ? : 125048 3905 128953
@sbcs && !@xbcs ? : 3905 0 3905
Condition55%5/9
@sbcs and @xbcs
!ll&&!rl&&r
12504839050
not @sbcs and @xbcs
!ll&&!rl&&r
39050125048
@sbcs and not @xbcs
!ll&&!rl&&r
003905
MC/DC0%0/2
@sbcs and @xbcs
@sbcs @xbcs
MC/DC50%1/2
not @sbcs and @xbcs
not @sbcs @xbcs
MC/DC0%0/2
@sbcs and not @xbcs
@sbcs not @xbcs
Truth table66%2/3
A and B
A= @sbcsB= @xbcs
ABresult
0X0
100
111
Truth table66%2/3
not(A) and B
A= not @sbcsB= @xbcs
ABresult
0X0
100
111
Truth table33%1/3
A and not(B)
A= @sbcsB= not @xbcs
ABresult
0X0
100
111
526 elsif ($classmate eq '[:xdigit:]' ) { push @sbcs, '\x30-\x39\x41-\x46\x61-\x66'; }
527  
528 # [:^POSIX:]
529 elsif ($classmate eq '[:^alnum:]' ) { push @xbcs, "(?:(?![\\x30-\\x39\\x41-\\x5A\\x61-\\x7A])$x)"; }
530 elsif ($classmate eq '[:^alpha:]' ) { push @xbcs, "(?:(?![\\x41-\\x5A\\x61-\\x7A])$x)"; }
531 elsif ($classmate eq '[:^ascii:]' ) { push @xbcs, "(?:(?![\\x00-\\x7F])$x)"; }
532 elsif ($classmate eq '[:^blank:]' ) { push @xbcs, "(?:(?![\\x09\\x20])$x)"; }
533 elsif ($classmate eq '[:^cntrl:]' ) { push @xbcs, "(?:(?![\\x00-\\x1F\\x7F])$x)"; }
534 498 ▶ elsif ($classmate eq '[:^digit:]' ) { push @xbcs, "(?:(?![\\x30-\\x39])$x)"; }
Branch: 1 branch
BranchTrueFalseTotal
$modifiers =~ /s/ ? : 3 495 498
535 18 elsif ($classmate eq '[:^graph:]' ) { push @xbcs, "(?:(?![\\x21-\\x7F])$x)"; }
536 33 elsif ($classmate eq '[:^lower:]' ) { push @xbcs, "(?:(?![\\x61-\\x7A])$x)"; } # /i modifier requires 'a' to 'z' literally
537 24 elsif ($classmate eq '[:^print:]' ) { push @xbcs, "(?:(?![\\x20-\\x7F])$x)"; }
538 18 elsif ($classmate eq '[:^punct:]' ) { push @xbcs, "(?:(?![\\x21-\\x2F\\x3A-\\x3F\\x40\\x5B-\\x5F\\x60\\x7B-\\x7E])$x)"; }
539 39 elsif ($classmate eq '[:^space:]' ) { push @xbcs, "(?:(?![\\s\\x0B])$x)"; } # "\s" and vertical tab ("\cK")
540 24 elsif ($classmate eq '[:^upper:]' ) { push @xbcs, "(?:(?![\\x41-\\x5A])$x)"; } # /i modifier requires 'A' to 'Z' literally
541 24 elsif ($classmate eq '[:^word:]' ) { push @xbcs, "(?:(?![\\x30-\\x39\\x41-\\x5A\\x5F\\x61-\\x7A])$x)"; }
542 192 elsif ($classmate eq '[:^xdigit:]') { push @xbcs, "(?:(?![\\x30-\\x39\\x41-\\x46\\x61-\\x66])$x)"; }
543 18  
544 33 # other all
545 24 elsif (CORE::length($classmate)==1) { push @sbcs, $classmate }
546 24 else { push @xbcs, $classmate }
547 24 $i += 1;
548 192 }
549 }
550  
551 # [^...]
552 210172 ▶ if ($negative eq q[^]) {
Branch: 4 branches
BranchTrueFalseTotal
if (do { $after[-1] =~ /\A \\c [\x00-\xFF] \z/x }) { } 57 210115 210172
elsif ($after[-1] =~ /\A \\ [\x00-\xFF] \z/x) { } 171 209944 210115
elsif ($after[-1] =~ /\A [\x00-\xFF] \z/x) { } 209827 117 209944
elsif ($after[-1] =~ / [\x00-\xFF] [)}\]] \z/x) { } 114 3 117
553 push @after,
554 ( @sbcs and @xbcs) ? '(?:(?!' . join('|', @xbcs, '['.join('', @sbcs).']') . ")$x)" :
555 (!@sbcs and @xbcs) ? '(?:(?!' . join('|', @xbcs ) . ")$x)" :
556 ( @sbcs and !@xbcs) ? '(?:(?!' . '['.join('', @sbcs).']' . ")$x)" :
557 '';
558 3 }
559  
560 210172 # [...] on Perl 5.006
561 elsif ($] =~ /\A5\.006/) {
562 push @after,
563 ( @sbcs and @xbcs) ? '(?:' . join('|', @xbcs, '['.join('', @sbcs).']') . ')' :
564 (!@sbcs and @xbcs) ? '(?:' . join('|', @xbcs ) . ')' :
565 18 ( @sbcs and !@xbcs) ? '['.join('', @sbcs).']' :
566 '';
567 }
568  
569 # [...]
570 841836 else {
571 push @after,
572 ( @sbcs and @xbcs) ? '(?:(?=' . join('|', @xbcs, '['.join('', @sbcs).']') . ")$x)" :
573 (!@sbcs and @xbcs) ? '(?:(?=' . join('|', @xbcs ) . ")$x)" :
574 209731 ( @sbcs and !@xbcs) ? '['.join('', @sbcs).']' :
575 209731 '';
576 }
577 }
578  
579 # \any or /./
580 10 ▶ elsif ($before eq '.' ) { push @after, ($modifiers =~ /s/) ? $x : "(?:(?!\\n)$x)" }
Subroutine require: called CC=12 SCAR=32.9
Pod undocumented
581 10 ▶ elsif ($before eq '\B') { push @after, "(?:(?<![$bare_w])(?![$bare_w])|(?<=[$bare_w])(?=[$bare_w]))" }
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 10 0 10
582 elsif ($before eq '\D') { push @after, "(?:(?![$bare_d])$x)" }
583 elsif ($before eq '\H') { push @after, "(?:(?![$bare_h])$x)" }
584 10 ▶ elsif ($before eq '\N') { push @after, "(?:(?!\\n)$x)" }
Branch: 1 branch
BranchTrueFalseTotal
if (/^[0-9]/) { } 0 10 10
585 0 ▶ elsif ($before eq '\R') { push @after, "(?>\\r\\n|[$bare_v])" }
Branch: 1 branch
BranchTrueFalseTotal
if ($] < $_) { } 0 0 0
586 0 elsif ($before eq '\S') { push @after, "(?:(?![$bare_s])$x)" }
587 elsif ($before eq '\V') { push @after, "(?:(?![$bare_v])$x)" }
588 elsif ($before eq '\W') { push @after, "(?:(?![$bare_w])$x)" }
589 0 elsif ($before eq '\b') { push @after, "(?:(?<![$bare_w])(?=[$bare_w])|(?<=[$bare_w])(?![$bare_w]))" }
590 0 elsif ($before eq '\d') { push @after, "[$bare_d]" }
591 elsif ($before eq '\h') { push @after, "[$bare_h]" }
592 elsif ($before eq '\s') { push @after, "[$bare_s]" }
593 elsif ($before eq '\v') { push @after, "[$bare_v]" }
594 elsif ($before eq '\w') { push @after, "[$bare_w]" }
595  
596 # quantifiers ? + * {n} {n,} {n,m}
597 elsif ($before =~ /\A[?+*{]\z/) {
598 10 if (0) { }
599 10 ▶ elsif ($after[-1] =~ /\A \\c [\x00-\xFF] \z/x) { } # \c) \c} \c] \cX
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ s[::][/]g or not $file =~ m([\./\\])) 0 10 10
Condition33%1/3
$file =~ s[::][/]g or not $file =~ m([\./\\])
l!l&&r!l&&!r
0010
MC/DC0%0/2
$file =~ s[::][/]g or not $file =~ m([\./\\])
$file =~ s[::][/]g not $file =~ m([\./\\])
Truth table33%1/3
A or not(B)
A= $file =~ s[::][/]gB= not $file =~ m([\./\\])
ABresult
1X1
011
000
600 0 elsif ($after[-1] =~ /\A \\ [\x00-\xFF] \z/x) { } # \) \} \] \" \0 \1 \D \E \F \G \H \K \L \N \Q \R \S \U \V \W \\ \a \d \e \f \h \l \n \r \s \t \u \v \w
601 elsif ($after[-1] =~ /\A [\x00-\xFF] \z/x) { } # (a) a{1} [a] a . \012 \x12 \o{12} \g{1}
602 10 ▶ elsif ($after[-1] =~ / [\x00-\xFF] [)}\]] \z/x) { } # (any) any{1} [any]
Branch: 1 branch
BranchTrueFalseTotal
if (exists $INC{$file}) 2 8 10
603 2 else { # XBCS
604 2 ▶ $after[-1] = '(?:' . $after[-1] . ')';
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$file} 2 0 2
605 0 }
606 push @after, $before;
607 8 }
608 8 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (-f $prefix_file) 8 0 8
609 8 # \x{UTF8hex}
610 elsif ($before =~ /\A \\x \{ ([0123456789ABCDEFabcdef]+) \} \z/x) {
611 push @after, UTF8::R2::chr(hex $1);
612 }
613 8  
614 8 # else
615 else {
616 push @after, $before;
617 }
618 }
619  
620 my $after = join '', @after;
621 8 ▶ return qr/$after/;
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 8 8
elsif (not $result) { } 0 8 8
622 0 }
623 0  
624 #---------------------------------------------------------------------
625 # mb::require() like require(), mb.pm compatible
626 0 sub UTF8::R2::require (;$) {
627 0 local $_ = @_ ? $_[0] : $_;
628  
629 # require perl version
630 8 if (/^[0-9]/) {
631 if ($] < $_) {
632 confess "Perl $_ required--this is only version $], stopped";
633 }
634 0 else {
635 undef $@;
636 return 1;
637 }
638 }
639  
640 20 ▶ # require expr
Subroutine reverse: called CC=3 SCAR=11.0
Pod undocumented
641 else {
642  
643 20 ▶ # find expr in @INC
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 16 20
644 my $file = $_;
645 if (($file =~ s{::}{/}g) or ($file !~ m{[\./\\]})) {
646 4 $file .= '.pm';
647 }
648 if (exists $INC{$file}) {
649 undef $@;
650 return 1 if $INC{$file};
651 confess "Compilation failed in require";
652 }
653 16 ▶ for my $prefix_file ($file, map { "$_/$file" } @INC) {
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 8 8 16
654 if (-f $prefix_file) {
655 $INC{$_} = $prefix_file;
656  
657 # run as Perl script
658 # must use CORE::do to use <DATA>, because CORE::eval cannot do it.
659 local $@;
660 my $result = CORE::eval sprintf(<<'END', (caller)[0, 2, 1]);
661 package %s;
662 #line %s "%s"
663 CORE::do "$prefix_file";
664 END
665 16 ▶ 
Subroutine rindex: called CC=3 SCAR=11.0
Pod undocumented
666 16 # return result
667 16 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) { } 8 8 16
668 8 $INC{$_} = undef;
669 confess $@;
670 }
671 8 elsif (not $result) {
672 delete $INC{$_};
673 16 ▶ confess "$_ did not return true value";
Branch: 1 branch
BranchTrueFalseTotal
if ($rindex == -1) { } 8 8 16
674 8 }
675 else {
676 return $result;
677 8 }
678 }
679 }
680 confess "Can't find $_ in \@INC";
681 }
682 }
683 16 ▶ 
Subroutine rindex_byte: called CC=2 SCAR=6.9
Pod undocumented
684 16 ▶#---------------------------------------------------------------------
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) { } 8 8 16
685 8 # reverse() for UTF-8 codepoint string
686 sub UTF8::R2::reverse (@) {
687  
688 8 # in list context,
689 if (wantarray) {
690  
691 # returns a list value consisting of the elements of @_ in the opposite order
692 return CORE::reverse @_;
693 }
694 112 ▶ 
Subroutine split: called CC=14 SCAR=28.4
Pod documented
695 112 ▶ # in scalar context,
Branch: 4 branches
BranchTrueFalseTotal
if (defined $_[0] and $_[0] eq '' || $_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x) { } 76 36 112
elsif (@_ == 3) { } 24 12 36
elsif (@_ == 2) { } 12 0 12
elsif (@_ == 1) { } 0 0 0
Condition83%5/6
defined $_[0] and $_[0] eq "" || $_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x
!ll&&!rl&&r
03676
$_[0] eq "" or $_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x
l!l&&r!l&&!r
245236
MC/DC66%2/3
defined $_[0] and $_[0] eq "" || $_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x
defined $_[0] $_[0] eq "" $_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x
Truth table75%3/4
A and B or C
A= defined $_[0]B= $_[0] eq ""C= $_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x
ABCresult
0XX0
1000
11X1
1011
696 76 ▶ else {
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 60 16 76
697 76 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[2] and $_[2] > 0 and scalar @x > $_[2]) 24 52 76
Condition100%6/6
defined $_[2] and $_[2] > 0 and scalar @x > $_[2]
!ll&&!rl&&r
44824
defined $_[2] and $_[2] > 0
!ll&&!rl&&r
40432
MC/DC100%3/3
defined $_[2] and $_[2] > 0 and scalar @x > $_[2]
defined $_[2] $_[2] > 0 scalar @x > $_[2]
Truth table100%4/4
A and B and C
A= defined $_[2]B= $_[2] > 0C= scalar @x > $_[2]
ABCresult
0XX0
10X0
1100
1111
698 24 # returns a string value with all characters in the opposite order of
699 return (join '',
700 76 ▶ CORE::reverse(
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 52 24 76
701 52 @_ ?
702 join('', @_) =~ /\G$x/g : # concatenates the elements of @_
703 /\G$x/g # $_ when without arguments
704 24 ▶ )
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.012") 0 24 24
705 0 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
if $^W 0 0 0
706 0 }
707 }
708 24  
709 #---------------------------------------------------------------------
710 # rindex() for UTF-8 codepoint string
711 sub UTF8::R2::rindex ($$;$) {
712 24 my $rindex = 0;
713 if (@_ == 3) {
714 $rindex = CORE::rindex $_[0], $_[1], CORE::length(UTF8::R2::substr($_[0], 0, $_[2]));
715 12 }
716 else {
717 $rindex = CORE::rindex $_[0], $_[1];
718 0 }
719 if ($rindex == -1) {
720 return -1;
721 0 }
722 else {
723 return UTF8::R2::length(CORE::substr $_[0], 0, $rindex);
724 }
725 }
726  
727 116 ▶#---------------------------------------------------------------------
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine substr: called CC=11 SCAR=24.0
Pod undocumented
Branch: 10 branches
BranchTrueFalseTotal
if ($_[1] < -1 * scalar(@x) or 1 * scalar(@x) < $_[1]) 4 112 116
if (@_ == 4) { } 32 80 112
elsif (@_ == 3) { } 64 16 80
$_[1] < 0 ? : 16 48 64
$_[1] > 0 ? : 16 32 48
$_[2] < 0 ? : 16 48 64
$_[2] > 0 ? : 48 0 48
$_[1] < 0 ? : 8 8 16
$_[1] > 0 ? : 8 0 8
$] >= 5.014 ? : 70 0 70
Condition100%3/3
$_[1] < -1 * scalar(@x) or 1 * scalar(@x) < $_[1]
l!l&&r!l&&!r
22112
MC/DC100%2/2
$_[1] < -1 * scalar(@x) or 1 * scalar(@x) < $_[1]
$_[1] < -1 * scalar(@x) 1 * scalar(@x) < $_[1]
Truth table100%3/3
A or B
A= $_[1] < -1 * scalar(@x)B= 1 * scalar(@x) < $_[1]
ABresult
1X1
011
000
728 # JPerl like rindex() for UTF-8 codepoint string
729 sub UTF8::R2::rindex_byte ($$;$) {
730 if (@_ == 3) {
731 return CORE::rindex $_[0], $_[1], CORE::length(UTF8::R2::substr($_[0], 0, $_[2]));
732 }
733 else {
734 return CORE::rindex $_[0], $_[1];
735 }
736 }
737  
738 #---------------------------------------------------------------------
739 # split() for UTF-8 codepoint string
740 sub UTF8::R2::split (;$$$) {
741 if (defined($_[0]) and (($_[0] eq '') or ($_[0] =~ /\A \( \? \^? [-a-z]* : \) \z/x))) {
742 my @x = (defined($_[1]) ? $_[1] : $_) =~ /\G$x/g;
743 if (defined($_[2]) and ($_[2] > 0) and (scalar(@x) > $_[2])) {
744 @x = (@x[0..$_[2]-1-1], join('', @x[$_[2]-1..$#x]));
745 }
746 if (wantarray) {
747 return @x;
748 }
749 else {
750 if ($] < 5.012) {
751 warn "Use of implicit split to \@_ is deprecated" if $^W;
752 @_ = @x; # unlike camel book and perldoc saying, can return only scalar(@_), cannot @_
753 }
754 return scalar @x;
755 }
756 }
757 elsif (@_ == 3) {
758 return CORE::split UTF8::R2::qr($_[0]), $_[1], $_[2];
759 }
760 elsif (@_ == 2) {
761 return CORE::split UTF8::R2::qr($_[0]), $_[1];
762 }
763 elsif (@_ == 1) {
764 return CORE::split UTF8::R2::qr($_[0]);
765 }
766 else {
767 return CORE::split;
768 }
769 }
770  
771 #---------------------------------------------------------------------
772 # substr() for UTF-8 codepoint string
773 CORE::eval sprintf <<'END', ($] >= 5.014) ? ':lvalue' : '';
774 # vv--------------*******
775 sub UTF8::R2::substr ($$;$$) %s {
776 my @x = $_[0] =~ /\G$x/g;
777  
778 # If the substring is beyond either end of the string, substr() returns the undefined
779 860 ▶ # value and produces a warning. When used as an lvalue, specifying a substring that
Subroutine list_all_ASCII_by_hyphen: called CC=11 SCAR=26.8
Pod undocumented
780 860 # is entirely outside the string raises an exception.
781 860 # http://perldoc.perl.org/functions/substr.html
782 860 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#hyphened) 1884 860 2744
783 1884 ▶ # A return with no argument returns the scalar value undef in scalar context,
Branch: 1 branch
BranchTrueFalseTotal
if ($i + 1 < $#hyphened and $hyphened[$i + 1] eq '-' and 1) { } 8 1876 1884
Condition100%5/5
$i + 1 < $#hyphened and $hyphened[$i + 1] eq "-" and 1
!ll
18768
$i + 1 < $#hyphened and $hyphened[$i + 1] eq "-"
!ll&&!rl&&r
14963808
MC/DC100%2/2
$i + 1 < $#hyphened and $hyphened[$i + 1] eq "-" and 1
$i + 1 < $#hyphened $hyphened[$i + 1] eq "-"
Truth table100%3/3
A and B
A= $i + 1 < $#hyphenedB= $hyphened[$i + 1] eq "-"
ABresult
0X0
100
111
784 # an empty list () in list context, and (naturally) nothing at all in void
785 # context.
786  
787 8 ▶ if (($_[1] < (-1 * scalar(@x))) or (+1 * scalar(@x) < $_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
$hyphened[$i + 0] eq '\\-' ? : 0 8 8
788 8 ▶ return;
Branch: 1 branch
BranchTrueFalseTotal
$hyphened[$i + 2] eq '\\-' ? : 0 8 8
789 8 ▶ }
Branch: 3 branches
BranchTrueFalseTotal
if (do { not $hyphened[$i + 0] =~ /\A [\x00-\x7F] \z/msx }) { } 0 8 8
elsif (not $hyphened[$i + 2] =~ /\A [\x00-\x7F] \z/msx) { } 0 8 8
elsif ($hyphened[$i + 0] gt $hyphened[$i + 2]) { } 0 8 8
790  
791 0 # substr($string,$offset,$length,$replacement)
792 if (@_ == 4) {
793 my $substr = join '', splice @x, $_[1], $_[2], $_[3];
794 0 $_[0] = join '', @x;
795 $substr; # "return $substr" doesn't work, don't write "return"
796 }
797 0  
798 # substr($string,$offset,$length)
799 elsif (@_ == 3) {
800 8 local $SIG{__WARN__} = sub {}; # avoid: Use of uninitialized value in join or string at here
801 8 my $octet_offset =
802 ($_[1] < 0) ? -1 * CORE::length(join '', @x[$#x+$_[1]+1 .. $#x]) :
803 ($_[1] > 0) ? CORE::length(join '', @x[0 .. $_[1]-1]) :
804 0;
805 1876 ▶ my $octet_length =
Branch: 1 branch
BranchTrueFalseTotal
if ($hyphened[$i] eq '\\-') { } 0 1876 1876
806 0 ($_[2] < 0) ? -1 * CORE::length(join '', @x[$#x+$_[2]+1 .. $#x]) :
807 ($_[2] > 0) ? CORE::length(join '', @x[$_[1] .. $_[1]+$_[2]-1]) :
808 0;
809 1876 CORE::substr($_[0], $octet_offset, $octet_length);
810 }
811 1876  
812 # substr($string,$offset)
813 else {
814 860 my $octet_offset =
815 ($_[1] < 0) ? -1 * CORE::length(join '', @x[$#x+$_[1]+1 .. $#x]) :
816 ($_[1] > 0) ? CORE::length(join '', @x[0 .. $_[1]-1]) :
817 0;
818 CORE::substr($_[0], $octet_offset);
819 430 ▶ }
Subroutine tr: called CC=30 SCAR=34.1
Pod documented
820 430 }
821 430 END
822 430  
823 430 ▶#---------------------------------------------------------------------
Branch: 1 branch
BranchTrueFalseTotal
defined $_[3] ? : 340 90 430
824 # tr/A-C/1-3/ for UTF-8 codepoint
825 430 sub list_all_ASCII_by_hyphen {
826 430 ▶ my @hyphened = @_;
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#search) 1026 430 1456
827 my @list_all = ();
828 for (my $i=0; $i <= $#hyphened; ) {
829 1026 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $tr{$search[$i]}) 938 88 1026
830 ($i+1 < $#hyphened) and
831 ($hyphened[$i+1] eq '-') and
832 938 ▶ 1) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $replacement[$i] and $replacement[$i] ne '') { } 774 164 938
elsif (exists $modifier{'d'}) { } 92 72 164
elsif (defined $replacement[-1] and $replacement[-1] ne '') { } 56 16 72
Condition66%2/3
defined $replacement[$i] and $replacement[$i] ne ""
!ll&&!rl&&r
1640774
MC/DC50%1/2
defined $replacement[$i] and $replacement[$i] ne ""
defined $replacement[$i] $replacement[$i] ne ""
Truth table66%2/3
A and B
A= defined $replacement[$i]B= $replacement[$i] ne ""
ABresult
0X0
100
111
833 774 $hyphened[$i+0] = ($hyphened[$i+0] eq '\\-') ? '-' : $hyphened[$i+0];
834 $hyphened[$i+2] = ($hyphened[$i+2] eq '\\-') ? '-' : $hyphened[$i+2];
835 if (0) { }
836 elsif ($hyphened[$i+0] !~ m/\A [\x00-\x7F] \z/xms) {
837 confess sprintf(qq{@{[__FILE__]}: "$hyphened[$i+0]-$hyphened[$i+2]" in tr range is not US-ASCII});
838 92 }
839 elsif ($hyphened[$i+2] !~ m/\A [\x00-\x7F] \z/xms) {
840 confess sprintf(qq{@{[__FILE__]}: "$hyphened[$i+0]-$hyphened[$i+2]" in tr range is not US-ASCII});
841 }
842 ▶ elsif ($hyphened[$i+0] gt $hyphened[$i+2]) {
Condition66%2/3
defined $replacement[-1] and $replacement[-1] ne ""
!ll&&!rl&&r
16056
MC/DC50%1/2
defined $replacement[-1] and $replacement[-1] ne ""
defined $replacement[-1] $replacement[-1] ne ""
Truth table66%2/3
A and B
A= defined $replacement[-1]B= $replacement[-1] ne ""
ABresult
0X0
100
111
843 56 confess sprintf(qq{@{[__FILE__]}: "$hyphened[$i+0]-$hyphened[$i+2]" in tr range is not "$hyphened[$i+0]" le "$hyphened[$i+2]"});
844 }
845 else {
846 push @list_all, map { CORE::chr($_) } (CORE::ord($hyphened[$i+0]) .. CORE::ord($hyphened[$i+2]));
847 $i += 3;
848 16 }
849 }
850 else {
851 if ($hyphened[$i] eq '\\-') {
852 push @list_all, '-';
853 430 }
854 430 else {
855 push @list_all, $hyphened[$i];
856 }
857 430 ▶ $i++;
Branch: 1 branch
BranchTrueFalseTotal
if (exists $modifier{'c'}) { } 156 274 430
858 }
859 }
860 156 ▶ return @list_all;
Branch: 1 branch
BranchTrueFalseTotal
if (exists $modifier{'s'}) { } 72 84 156
861 72 }
862 72 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @x)) 648 72 720
863 #---------------------------------------------------------------------
864 # tr/// for UTF-8 codepoint string
865 648 ▶sub UTF8::R2::tr ($$$;$) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tr{$x}) { } 360 288 648
866 360 my @x = $_[0] =~ /\G($x)/xmsg;
867 360 my @search = list_all_ASCII_by_hyphen($_[1] =~ /\G(\\-|$x)/xmsg);
868 my @replacement = list_all_ASCII_by_hyphen($_[2] =~ /\G(\\-|$x)/xmsg);
869 my %modifier = (defined $_[3]) ? (map { $_ => 1 } CORE::split('', $_[3])) : ();
870  
871 my %tr = ();
872 288 ▶ for (my $i=0; $i <= $#search; $i++) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $modifier{'d'}) { } 216 72 288
elsif (defined $replacement[-1]) { } 72 0 72
873  
874 # tr/AAA/123/ works as tr/A/1/
875 if (not exists $tr{$search[$i]}) {
876  
877 # tr/ABC/123/ makes %tr = ('A'=>'1','B'=>'2','C'=>'3',);
878 72 ▶ if (defined($replacement[$i]) and ($replacement[$i] ne '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last_transliterated and $replacement[-1] eq $last_transliterated) { } 0 72 72
Condition33%1/3
defined $last_transliterated and $replacement[-1] eq $last_transliterated
!ll&&!rl&&r
7200
MC/DC0%0/2
defined $last_transliterated and $replacement[-1] eq $last_transliterated
defined $last_transliterated $replacement[-1] eq $last_transliterated
Truth table33%1/3
A and B
A= defined $last_transliteratedB= $replacement[-1] eq $last_transliterated
ABresult
0X0
100
111
879 $tr{$search[$i]} = $replacement[$i];
880 }
881  
882 # tr/ABC/12/d makes %tr = ('A'=>'1','B'=>'2','C'=>'',);
883 72 elsif (exists $modifier{d}) {
884 $tr{$search[$i]} = '';
885 }
886 288  
887 # tr/ABC/12/ makes %tr = ('A'=>'1','B'=>'2','C'=>'2',);
888 elsif (defined($replacement[-1]) and ($replacement[-1] ne '')) {
889 $tr{$search[$i]} = $replacement[-1];
890 }
891  
892 # tr/ABC// makes %tr = ('A'=>'A','B'=>'B','C'=>'C',);
893 84 ▶ else {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @x)) 540 84 624
894 $tr{$search[$i]} = $search[$i];
895 }
896 540 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tr{$x}) { } 396 144 540
897 396 }
898  
899 my $tr = 0;
900 my $replaced = '';
901  
902 144 ▶ # has /c modifier
Branch: 2 branches
BranchTrueFalseTotal
if (exists $modifier{'d'}) { } 36 108 144
elsif (defined $replacement[-1]) { } 108 0 108
903 if (exists $modifier{c}) {
904  
905 # has /s modifier
906 if (exists $modifier{s}) {
907 108 my $last_transliterated = undef;
908 while (defined(my $x = shift @x)) {
909 144  
910 # /c modifier works here
911 if (exists $tr{$x}) {
912 $replaced .= $x;
913 $last_transliterated = undef;
914 }
915 else {
916  
917 # /d modifier works here
918 if (exists $modifier{d}) {
919 274 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $modifier{'s'}) { } 144 130 274
920 144  
921 144 ▶ elsif (defined $replacement[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @x)) 1008 144 1152
922 1008 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tr{$x}) { } 712 296 1008
923 # /s modifier works here
924 if (defined($last_transliterated) and ($replacement[-1] eq $last_transliterated)) {
925 712 ▶ }
Branch: 2 branches
BranchTrueFalseTotal
if ($tr{$x} eq '') { } 156 556 712
elsif (defined $last_transliterated and $tr{$x} eq $last_transliterated) { } 280 276 556
926  
927 # tr/// works here
928 else {
929 ▶ $replaced .= ($last_transliterated = $replacement[-1]);
Condition100%3/3
defined $last_transliterated and $tr{$x} eq $last_transliterated
!ll&&!rl&&r
24036280
MC/DC100%2/2
defined $last_transliterated and $tr{$x} eq $last_transliterated
defined $last_transliterated $tr{$x} eq $last_transliterated
Truth table100%3/3
A and B
A= defined $last_transliteratedB= $tr{$x} eq $last_transliterated
ABresult
0X0
100
111
930 }
931 }
932 $tr++;
933 }
934 276 }
935 }
936 712  
937 # has no /s modifier
938 else {
939 296 while (defined(my $x = shift @x)) {
940 296  
941 # /c modifier works here
942 if (exists $tr{$x}) {
943 $replaced .= $x;
944 }
945 else {
946  
947 130 ▶ # /d modifier works here
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $x = shift @x)) 970 130 1100
948 970 ▶ if (exists $modifier{d}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tr{$x}) { } 710 260 970
949 710 }
950 710  
951 # tr/// works here
952 elsif (defined $replacement[-1]) {
953 260 $replaced .= $replacement[-1];
954 }
955 $tr++;
956 }
957 }
958 }
959 }
960 430 ▶ 
Branch: 1 branch
BranchTrueFalseTotal
if (exists $modifier{'r'}) { } 104 326 430
961 104 # has no /c modifier
962 else {
963  
964 # has /s modifier
965 if (exists $modifier{s}) {
966 326 my $last_transliterated = undef;
967 326 while (defined(my $x = shift @x)) {
968 if (exists $tr{$x}) {
969  
970 # /d modifier works here
971 if ($tr{$x} eq '') {
972 }
973 4 ▶ 
Subroutine uc: called CC=3 SCAR=11.0
Pod undocumented
974 4 ▶ # /s modifier works here
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3 1 4
975 elsif (defined($last_transliterated) and ($tr{$x} eq $last_transliterated)) {
976 4 ▶ }
Condition66%2/3
{'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z'}->{$_} || $_
l!l&&r!l&&!r
54520
MC/DC0%0/2
{'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z'}->{$_} || $_
{'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z'}->{$_} $_
Truth table66%2/3
A || B
A= {'a', 'A', 'b', 'B', 'c', 'C', 'd', 'D', 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'o', 'O', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 't', 'T', 'u', 'U', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z'}->{$_}B= $_
ABresult
1X1
011
000
977  
978 # tr/// works here
979 else {
980 $replaced .= ($last_transliterated = $tr{$x});
981 }
982 2 ▶ $tr++;
Subroutine ucfirst: called CC=3 SCAR=11.4
Pod undocumented
983 2 ▶ }
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 1 2
984 2 ▶ else {
Branch: 1 branch
BranchTrueFalseTotal
if (/\A($x)(.*)\z/s) { } 2 0 2
985 2 $replaced .= $x;
986 $last_transliterated = undef;
987 }
988 0 }
989 }
990  
991 # has no /s modifier
992 else {
993 while (defined(my $x = shift @x)) {
994 if (exists $tr{$x}) {
995 $replaced .= $tr{$x};
996 $tr++;
997 }
998 else {
999 35 ▶ $replaced .= $x;
Subroutine TIEHASH: called CC=1 SCAR=0.0
1000 209022 ▶ }
Subroutine FETCH: called CC=1 SCAR=0.0
1001 0 ▶ }
Subroutine STORE: not called CC=1 SCAR=0.0
1002 0 ▶ }
Subroutine FIRSTKEY: not called CC=1 SCAR=0.0
1003 0 ▶ }
Subroutine NEXTKEY: not called CC=1 SCAR=0.0
1004 0 ▶ 
Subroutine EXISTS: not called CC=1 SCAR=0.0
1005 0 ▶ # /r modifier works here
Subroutine DELETE: not called CC=1 SCAR=0.0
1006 0 ▶ if (exists $modifier{r}) {
Subroutine CLEAR: not called CC=1 SCAR=0.0
1007 0 ▶ return $replaced;
Subroutine UNTIE: not called CC=1 SCAR=0.0
1008 0 ▶ }
Subroutine DESTROY: not called CC=1 SCAR=0.0
1009 0 ▶ 
Subroutine SCALAR: not called CC=1 SCAR=0.0
1010 # has no /r modifier
1011 70 else {
1012 $_[0] = $replaced;
1013 return $tr;
1014 }
1015 }
1016  
1017 #---------------------------------------------------------------------
1018 # universal uc() for UTF-8 codepoint string
1019 sub UTF8::R2::uc (;$) {
1020 local $_ = @_ ? $_[0] : $_;
1021 # a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z
1022 return join '', map { {qw( a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z )}->{$_}||$_ } /\G$x/g;
1023 # a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z
1024 }
1025  
1026 #---------------------------------------------------------------------
1027 # universal ucfirst() for UTF-8 codepoint string
1028 sub UTF8::R2::ucfirst (;$) {
1029 local $_ = @_ ? $_[0] : $_;
1030 if (/\A($x)(.*)\z/s) {
1031 return UTF8::R2::uc($1) . $2;
1032 }
1033 else {
1034 return '';
1035 }
1036 }
1037  
1038 # syntax sugar for UTF-8 codepoint regex
1039 #
1040 # tie my %mb, 'UTF8::R2';
1041 # $result = $_ =~ $mb{qr/$utf8regex/imsxo}
1042 # $result = $_ =~ m<\G$mb{qr/$utf8regex/imsxo}>gc
1043 # $result = $_ =~ s<$mb{qr/before/imsxo}><after>egr
1044  
1045 sub TIEHASH { bless { }, $_[0] }
1046 sub FETCH { UTF8::R2::qr $_[1] }
1047 sub STORE { }
1048 sub FIRSTKEY { }
1049 sub NEXTKEY { }
1050 sub EXISTS { }
1051 sub DELETE { }
1052 sub CLEAR { }
1053 sub UNTIE { }
1054 sub DESTROY { }
1055 sub SCALAR { }
1056  
1057 1;
1058  
1059 __END__
↑ Summary