Multibyte.pm

filter: Statementstmt 93.3% 307 / 329 Branchbran 80.4% 288 / 358 Conditioncond 70.9% 78 / 110 MC/DCmcdc 43.0% 31 / 72 Subroutinesub 96.4% 27 / 28 Podpod 100% 13 / 13 totaltotal 81.7% 744 / 910 CC 221 SCAR 29.0
CC
221
Cov
84%
strsplit
34.4
trclosure
30.3
substr
25.4
CRAP 18.1
« Multibyte/UTF8.pm ↑ Summary Multibyte/EUC_JP.pm »
1 package String::Multibyte;
2  
3 #
4 # /o never allowed!
5 #
6  
7 22 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 if (ord("A") == 193) {
9 die "String::Multibyte not ported to EBCDIC\n";
10 }
11 }
12  
13 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 22 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 22 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 22 require Exporter;
17  
18 22 @ISA = qw(Exporter);
19 22 @EXPORT = qw();
20  
21 22 $VERSION = '1.12';
22  
23 22 my $PACKAGE = 'String::Multibyte'; # __PACKAGE__
24  
25 22 my $Msg_malfo = $PACKAGE ." malformed %s character";
26 22 my $Msg_undef = $PACKAGE ." undefined %s";
27 22 my $Msg_panic = $PACKAGE ." panic in %s";
28 22 my $Msg_revrs = $PACKAGE ." reverse in %s";
29 22 my $Msg_outstr = $PACKAGE ." substr outside of string";
30 22 my $Msg_lastc = $PACKAGE ." reach the last char before end of char range";
31  
32 22 (my $Path = $INC{'String/Multibyte.pm'}) =~ s/\.pm$//;
33  
34 22 ▶use vars qw($hasFS);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 22 eval { require File::Spec; };
36 22 ▶$hasFS = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 0 22 22
37  
38 #==========
39 # new
40 #
41 148 ▶sub new {
Subroutine new: called CC=8 SCAR=21.1
Pod documented
42 148 my $class = shift;
43 148 my $charset = shift;
44 148 my $verbose = shift;
45 148 my ($pm, $self);
46 148 ▶ if (ref $charset) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $charset) { } 8 140 148
47 8 $self = { %$charset };
48 } else {
49 140 ▶ $pm = $hasFS
Branch: 1 branch
BranchTrueFalseTotal
$String::Multibyte::hasFS ? : 140 0 140
50 ? File::Spec->catfile($Path, "$charset.pm")
51 : "$Path/$charset.pm";
52 140 ▶ $self = do($pm) or croak "not exist $pm";
Branch: 1 branch
BranchTrueFalseTotal
$self = do $pm or croak("not exist $pm") 140 0 140
53 }
54 defined $self->{regexp}
55 148 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 148 0 148
56 148 ▶ $] < 5.005
Branch: 1 branch
BranchTrueFalseTotal
$] < "5.005" or eval " \$self->{regexp} = qr/\$self->{regexp}/; " 0 148 148
57 or eval q{ $self->{regexp} = qr/$self->{regexp}/; };
58  
59 148 ▶ $verbose and $self->{verbose} = $verbose;
Branch: 1 branch
BranchTrueFalseTotal
$verbose and $self->{"verbose"} = $verbose 144 4 148
60 defined $self->{charset}
61 148 ▶ or $self->{charset} = "$charset"; # stringified
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"charset"} or $self->{"charset"} = "$charset" 147 1 148
62 148 return bless $self, $class;
63 }
64  
65 #==========
66 # islegal
67 #
68 47127 ▶sub islegal {
Subroutine islegal: called CC=4 SCAR=13.9
Pod documented
69 47127 my $obj = shift;
70 my $re = $obj->{regexp}
71 47127 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 47127 0 47127
72 47127 for (@_) {
73 64791 my $str = $_;
74 64791 $str =~ s/$re//g;
75 64791 ▶ return '' if CORE::length($str);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $str 43 64748 64791
76 }
77 47084 return 1;
78 }
79  
80 #==========
81 # length
82 #
83 118 ▶sub length {
Subroutine length: called CC=4 SCAR=15.0
Pod documented
84 118 my $obj = shift;
85 118 my $str = shift;
86 my $re = $obj->{regexp}
87 118 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 118 0 118
88  
89 118 ▶ if ($obj->{verbose} && ! $obj->islegal($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str)) 0 118 118
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal($str)
!ll&&!rl&&r
11170
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str)
$obj->{"verbose"} not $obj->islegal($str)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str)
ABresult
0X0
100
111
90 0 carp sprintf $Msg_malfo, $obj->{charset};
91 }
92 118 return 0 + $str =~ s/$re//g;
93 }
94  
95 #==========
96 # __strlen: for internal use
97 #
98 14231 ▶sub __strlen {
Subroutine __strlen: called CC=1 SCAR=0.0
99 14231 my ($re, $str) = @_;
100 14231 return 0 + $str =~ s/$re//g;
101 }
102  
103  
104 #==========
105 # strrev
106 #
107 54 ▶sub strrev {
Subroutine strrev: called CC=4 SCAR=15.0
Pod documented
108 54 my $obj = shift;
109 54 my $str = shift;
110 my $re = $obj->{regexp}
111 54 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 54 0 54
112  
113 54 ▶ if ($obj->{verbose} && ! $obj->islegal($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str)) 0 54 54
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal($str)
!ll&&!rl&&r
1530
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str)
$obj->{"verbose"} not $obj->islegal($str)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str)
ABresult
0X0
100
111
114 0 carp sprintf $Msg_malfo, $obj->{charset};
115 }
116 54 return join '', reverse $str =~ /$re/g;
117 }
118  
119  
120 #==========
121 # _check_n($re, $str, $sub, $len), internally used, non-OO
122 #
123 # like ($obj->substr($str, 0, $len) eq $sub);
124 # $len must be equal to $obj->length($sub);
125 #
126 4828 ▶sub _check_n {
Subroutine _check_n: called CC=3 SCAR=11.0
127 4828 my($re, $str, $sub, $len) = @_;
128 4828 my $cnt = 0;
129 4828 my $temp = "";
130 4828 ▶ while ($str =~ /($re)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /($re)/g) 13587 147 13734
131 13587 ▶ last unless $cnt < $len;
Branch: 1 branch
BranchTrueFalseTotal
unless $cnt < $len 4681 8906 13587
132 8906 $temp .= $1;
133 8906 $cnt++;
134 }
135 4828 return $sub eq $temp;
136 }
137  
138 #==========
139 # index
140 #
141 553 ▶sub index {
Subroutine index: called CC=17 SCAR=28.6
Pod documented
142 553 my $obj = shift;
143 my $re = $obj->{regexp}
144 553 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 553 0 553
145  
146 553 my $cnt = 0;
147 553 my($str,$sub) = @_;
148 553 ▶ if ($obj->{verbose} && ! $obj->islegal($str, $sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str, $sub)) 0 553 553
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal($str, $sub)
!ll&&!rl&&r
175360
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str, $sub)
$obj->{"verbose"} not $obj->islegal($str, $sub)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str, $sub)
ABresult
0X0
100
111
149 0 carp sprintf $Msg_malfo, $obj->{charset};
150 }
151 553 my $len = __strlen($re, $str);
152 553 ▶ my $pos = @_ == 3 ? $_[2] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 486 67 553
153  
154 553 ▶ if ($sub eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "") 117 436 553
155 117 ▶ return $pos <= 0 ? 0 : $len < $pos ? $len : $pos;
Branch: 2 branches
BranchTrueFalseTotal
$pos <= 0 ? : 65 52 117
$len < $pos ? : 30 22 52
156 }
157 436 ▶ return -1 if $len < $pos;
Branch: 1 branch
BranchTrueFalseTotal
if $len < $pos 32 404 436
158 404 my $pat = quotemeta($sub);
159 404 my $sublen = __strlen($re, $sub);
160 404 ▶ $str =~ s/^$re// ? $cnt++ : croak
Branch: 2 branches
BranchTrueFalseTotal
CORE::length $str and $cnt < $pos and do { $str =~ s/^$re// ? ++$cnt : croak() } 1806 404 2210
$str =~ s/^$re// ? : 1806 0 1806
Condition100%3/3
CORE::length $str and $cnt < $pos
!ll&&!rl&&r
443601806
MC/DC100%2/2
CORE::length $str and $cnt < $pos
CORE::length $str $cnt < $pos
Truth table100%3/3
A and B
A= CORE::length $strB= $cnt < $pos
ABresult
0X0
100
111
161 while CORE::length($str) && $cnt < $pos;
162 404 ▶ while (CORE::length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length $str) 71179 80 71259
163 last
164 71179 ▶ if $str =~ /^$pat/ && _check_n($re, $str, $sub, $sublen);
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen) 324 70855 71179
Condition100%3/3
$str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)
!ll&&!rl&&r
708514324
MC/DC100%2/2
$str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)
$str =~ /^$pat/ _check_n($re, $str, $sub, $sublen)
Truth table100%3/3
A and B
A= $str =~ /^$pat/B= _check_n($re, $str, $sub, $sublen)
ABresult
0X0
100
111
165 70855 ▶ $str =~ s/^$re// ? $cnt++ : croak;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^$re// ? : 70855 0 70855
166 }
167 404 ▶ return CORE::length($str) ? $cnt : -1;
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $str ? : 324 80 404
168 }
169  
170 #==========
171 # rindex
172 #
173 534 ▶sub rindex {
Subroutine rindex: called CC=14 SCAR=26.6
Pod documented
174 534 my $obj = shift;
175 my $re = $obj->{regexp}
176 534 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 534 0 534
177  
178 534 my $cnt = 0;
179 534 my($str,$sub) = @_;
180 534 ▶ if ($obj->{verbose} && ! $obj->islegal($str, $sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str, $sub)) 0 534 534
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal($str, $sub)
!ll&&!rl&&r
175170
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str, $sub)
$obj->{"verbose"} not $obj->islegal($str, $sub)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str, $sub)
ABresult
0X0
100
111
181 0 carp sprintf $Msg_malfo, $obj->{charset};
182 }
183 534 my $len = __strlen($re, $str);
184 534 ▶ my $pos = @_ == 3 ? $_[2] : $len;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 466 68 534
185 534 ▶ if ($sub eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "") 117 417 534
186 117 ▶ return $pos <= 0 ? 0 : $len <= $pos ? $len : $pos;
Branch: 2 branches
BranchTrueFalseTotal
$pos <= 0 ? : 53 64 117
$len <= $pos ? : 54 10 64
187 }
188 417 ▶ return -1 if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 122 295 417
189 295 my $pat = quotemeta($sub);
190 295 my $sublen = __strlen($re, $sub);
191 295 my $ret = -1;
192 295 ▶ while ($cnt <= $pos && CORE::length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt <= $pos and CORE::length $str) 71821 295 72116
Condition100%3/3
$cnt <= $pos and CORE::length $str
!ll&&!rl&&r
1999671821
MC/DC100%2/2
$cnt <= $pos and CORE::length $str
$cnt <= $pos CORE::length $str
Truth table100%3/3
A and B
A= $cnt <= $posB= CORE::length $str
ABresult
0X0
100
111
193 71821 ▶ $ret = $cnt
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen) 3805 68016 71821
Condition100%3/3
$str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)
!ll&&!rl&&r
6801153805
MC/DC100%2/2
$str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)
$str =~ /^$pat/ _check_n($re, $str, $sub, $sublen)
Truth table100%3/3
A and B
A= $str =~ /^$pat/B= _check_n($re, $str, $sub, $sublen)
ABresult
0X0
100
111
194 if $str =~ /^$pat/ && _check_n($re, $str, $sub, $sublen);
195 71821 ▶ $str =~ s/^$re// ? $cnt++ : croak;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^$re// ? : 71821 0 71821
196 }
197 295 return $ret;
198 }
199  
200 #==========
201 # _splitlist
202 #
203 84 ▶sub _splitlist {
Subroutine _splitlist: called CC=3 SCAR=11.0
204 84 my @ret;
205 84 my ($list, $re) = @_;
206 84 ▶ for (ref $list eq 'ARRAY' ? @$list : $list) {
Branch: 1 branch
BranchTrueFalseTotal
ref $list eq 'ARRAY' ? : 5 79 84
207 87 push @ret, /\G$re/g;
208 }
209 84 return @ret;
210 }
211  
212  
213 #==========
214 # strspn
215 #
216 46 ▶sub strspn {
Subroutine strspn: called CC=6 SCAR=18.5
Pod documented
217 46 my $obj = shift;
218 my $re = $obj->{regexp}
219 46 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 46 0 46
220  
221 46 my($str, $lst) = @_;
222 46 ▶ if ($obj->{verbose} && ! $obj->islegal($str, $lst)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str, $lst)) 0 46 46
Condition33%1/3
$obj->{"verbose"} and not $obj->islegal($str, $lst)
!ll&&!rl&&r
0460
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str, $lst)
$obj->{"verbose"} not $obj->islegal($str, $lst)
Truth table33%1/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str, $lst)
ABresult
0X0
100
111
223 0 carp sprintf $Msg_malfo, $obj->{charset};
224 }
225 46 my $ret = 0;
226 46 my(%lst);
227 46 @lst{ _splitlist($lst, $re) } = ();
228 46 ▶ while ($str =~ /($re)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /($re)/g) 35162 21 35183
229 35162 ▶ last unless exists $lst{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $lst{$1} 25 35137 35162
230 35137 $ret++;
231 }
232 46 return $ret;
233 }
234  
235  
236 #==========
237 # strcspn
238 #
239 38 ▶sub strcspn {
Subroutine strcspn: called CC=6 SCAR=18.5
Pod documented
240 38 my $obj = shift;
241 my $re = $obj->{regexp}
242 38 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 38 0 38
243  
244 38 my($str, $lst) = @_;
245 38 ▶ if ($obj->{verbose} && ! $obj->islegal($str, $lst)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str, $lst)) 0 38 38
Condition33%1/3
$obj->{"verbose"} and not $obj->islegal($str, $lst)
!ll&&!rl&&r
0380
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str, $lst)
$obj->{"verbose"} not $obj->islegal($str, $lst)
Truth table33%1/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str, $lst)
ABresult
0X0
100
111
246 0 carp sprintf $Msg_malfo, $obj->{charset};
247 }
248 38 my $ret = 0;
249 38 my(%lst);
250 38 @lst{ _splitlist($lst, $re) } = ();
251 38 ▶ while ($str =~ /($re)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /($re)/g) 35109 20 35129
252 35109 ▶ last if exists $lst{$1};
Branch: 1 branch
BranchTrueFalseTotal
if exists $lst{$1} 18 35091 35109
253 35091 $ret++;
254 }
255 38 return $ret;
256 }
257  
258 #==========
259 # substr
260 #
261 12319 ▶sub substr {
Subroutine substr: called CC=25 SCAR=32.4
Pod documented
262 12319 my $obj = shift;
263 my $re = $obj->{regexp}
264 12319 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 12319 0 12319
265 12319 my(@chars, $slen, $ini, $fin, $except);
266 12319 my $arg = $_[0];
267 12319 my $off = $_[1];
268 12319 my $len = $_[2];
269 12319 ▶ my $rep = @_ > 3 ? $_[3] : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ > 3 ? : 3570 8749 12319
270  
271 12319 ▶ my $str = ref $arg ? $$arg : $arg;
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 3910 8409 12319
272 12319 ▶ if ($obj->{verbose} && ! $obj->islegal($str, $rep)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str, $rep)) 0 12319 12319
Condition33%1/3
$obj->{"verbose"} and not $obj->islegal($str, $rep)
!ll&&!rl&&r
0123190
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str, $rep)
$obj->{"verbose"} not $obj->islegal($str, $rep)
Truth table33%1/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str, $rep)
ABresult
0X0
100
111
273 0 carp sprintf $Msg_malfo, $obj->{charset};
274 }
275  
276 12319 $slen = __strlen($re, $str);
277 12319 ▶ $except = 1 if $slen < $off;
Branch: 1 branch
BranchTrueFalseTotal
if $slen < $off 460 11859 12319
278 12319 ▶ if (@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 384 11935 12319
279 384 $len = $slen - $off;
280 } else {
281 11935 ▶ $except = 1 if $off + $slen < 0 && $len + $slen < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $off + $slen < 0 and $len + $slen < 0 40 11895 11935
Condition100%3/3
$off + $slen < 0 and $len + $slen < 0
!ll&&!rl&&r
1149540040
MC/DC100%2/2
$off + $slen < 0 and $len + $slen < 0
$off + $slen < 0 $len + $slen < 0
Truth table100%3/3
A and B
A= $off + $slen < 0B= $len + $slen < 0
ABresult
0X0
100
111
282 11935 ▶ $except = 1 if 0 <= $len && $off + $len + $slen < 0;
Branch: 1 branch
BranchTrueFalseTotal
if 0 <= $len and $off + $len + $slen < 0 50 11885 11935
Condition100%3/3
0 <= $len and $off + $len + $slen < 0
!ll&&!rl&&r
5500638550
MC/DC100%2/2
0 <= $len and $off + $len + $slen < 0
0 <= $len $off + $len + $slen < 0
Truth table100%3/3
A and B
A= 0 <= $lenB= $off + $len + $slen < 0
ABresult
0X0
100
111
283 }
284 12319 ▶ if ($except) {
Branch: 1 branch
BranchTrueFalseTotal
if ($except) 550 11769 12319
285 550 ▶ if(@_ > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) { } 0 550 550
286 0 croak $Msg_outstr;
287 } else {
288 550 return;
289 }
290 }
291 11769 ▶ $ini = $off < 0 ? $slen + $off : $off;
Branch: 1 branch
BranchTrueFalseTotal
$off < 0 ? : 5732 6037 11769
292 11769 ▶ $fin = $len < 0 ? $slen + $len : $ini + $len;
Branch: 1 branch
BranchTrueFalseTotal
$len < 0 ? : 5260 6509 11769
293 11769 ▶ $ini = 0 if $ini < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $ini < 0 370 11399 11769
294 11769 ▶ $fin = $ini if $ini > $fin;
Branch: 1 branch
BranchTrueFalseTotal
if $ini > $fin 2940 8829 11769
295 11769 ▶ $ini = $slen if $slen < $ini;
Branch: 1 branch
BranchTrueFalseTotal
if $slen < $ini 0 11769 11769
296 11769 ▶ $fin = $slen if $slen < $fin;
Branch: 1 branch
BranchTrueFalseTotal
if $slen < $fin 3132 8637 11769
297  
298 11769 my $cnt = 0;
299 11769 my $plen = 0;
300 11769 my $clen = 0;
301 11769 ▶ while ($str =~ /($re)/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /($re)/g) 122068 4165 126233
302 122068 ▶ if ($cnt < $ini) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cnt < $ini) { } 87888 34180 122068
elsif ($cnt < $fin) { } 26576 7604 34180
303 87888 $plen += CORE::length($1);
304 } elsif ($cnt < $fin) {
305 26576 $clen += CORE::length($1);
306 } else {
307 7604 last;
308 }
309 114464 $cnt++;
310 }
311 11769 ▶ my $temp = ref $arg
Branch: 1 branch
BranchTrueFalseTotal
ref $arg ? : 3910 7859 11769
312 ? \ CORE::substr($$arg, $plen, $clen)
313 : CORE::substr($str, $plen, $clen);
314  
315 11769 ▶ if (@_ > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) 3570 8199 11769
316 3570 $_[0] = CORE::substr($str, 0, $plen) .$rep.
317 CORE::substr($str, $plen + $clen);
318 }
319 11769 return $temp;
320 }
321  
322 #==========
323 # mkrange
324 #
325 6478 ▶sub mkrange {
Subroutine mkrange: called CC=19 SCAR=30.2
Pod documented
326 6478 my($s, @retv, $range);
327 6478 my $obj = shift;
328 my $re = $obj->{regexp}
329 6478 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 6478 0 6478
330 6478 my($str,$rev) = @_;
331 6478 ▶ my $hyp = exists $obj->{hyphen} ? $obj->{hyphen} : '-';
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'hyphen'} ? : 2558 3920 6478
332 6478 ▶ my $esc = exists $obj->{escape} ? $obj->{escape} : '\\';
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{'escape'} ? : 2558 3920 6478
333  
334 6478 ▶ if ($obj->{verbose} && ! $obj->islegal($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str)) 0 6478 6478
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal($str)
!ll&&!rl&&r
664720
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str)
$obj->{"verbose"} not $obj->islegal($str)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str)
ABresult
0X0
100
111
335 0 carp sprintf "$Msg_malfo in mkrange", $obj->{charset};
336 }
337 6478 ▶ if (!defined $obj->{nextchar}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj->{"nextchar"}) 22 6456 6478
338 22 ▶ return wantarray ? $str =~ /$re/g : $str;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 22 0 22
339 }
340 6456 $str =~ s/^\Q$hyp\E/$esc$hyp/;
341 6456 $range = 0;
342 6456 foreach $s ($str =~ /\G(?:\Q$esc$esc\E|\Q$esc$hyp\E|$re)/g) {
343 21673 ▶ if ($range) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range) { } 567 21106 21673
344 567 ▶ if ($s eq "$esc$hyp") {
Branch: 2 branches
BranchTrueFalseTotal
if ($s eq "$esc$hyp") { } 0 567 567
elsif ($s eq "$esc$esc") { } 0 567 567
345 0 $s = $hyp;
346 } elsif ($s eq "$esc$esc") {
347 0 $s = $esc;
348 }
349 567 ▶ my $p = @retv
Branch: 1 branch
BranchTrueFalseTotal
@retv ? : 567 0 567
350 ? pop(@retv)
351 : croak(sprintf $Msg_panic, "mkrange: Parse exception" .
352 "; no initial character in a range");
353 567 push @retv, $obj->__expand($p, $s, $rev);
354 567 $range = 0;
355 }
356 else {
357 21106 ▶ if ($s eq $hyp) {
Branch: 3 branches
BranchTrueFalseTotal
if ($s eq $hyp) { } 603 20503 21106
elsif ($s eq "$esc$hyp") { } 64 20439 20503
elsif ($s eq "$esc$esc") { } 36 20403 20439
358 603 $range = 1;
359 } elsif($s eq "$esc$hyp") {
360 64 push @retv, $hyp;
361 } elsif ($s eq "$esc$esc") {
362 36 push @retv, $esc;
363 } else {
364 20403 push @retv, $s;
365 }
366 }
367 }
368 6456 ▶ push @retv, $hyp if $range;
Branch: 1 branch
BranchTrueFalseTotal
if $range 36 6420 6456
369 6456 ▶ wantarray ? @retv : @retv ? join('', @retv) : '';
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 6118 338 6456
@retv ? : 329 9 338
370 }
371  
372 567 ▶sub __expand {
Subroutine __expand: called CC=7 SCAR=19.5
373 567 my $obj = shift;
374 567 my($fr,$to,$rev) = @_;
375  
376 567 ▶ if (defined $obj->{cmpchar} &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->{'cmpchar'} and &{$obj->{'cmpchar'};}($fr, $to) > 0) { } 57 510 567
Condition66%2/3
defined $obj->{"cmpchar"} and &{$obj->{"cmpchar"};}($fr, $to) > 0
!ll&&!rl&&r
051057
MC/DC50%1/2
defined $obj->{"cmpchar"} and &{$obj->{"cmpchar"};}($fr, $to) > 0
defined $obj->{"cmpchar"} &{$obj->{"cmpchar"};}($fr, $to) > 0
Truth table66%2/3
A and B
A= defined $obj->{"cmpchar"}B= &{$obj->{"cmpchar"};}($fr, $to) > 0
ABresult
0X0
100
111
377 567 &{ $obj->{cmpchar} }($fr,$to) > 0) {
378 57 ▶ return if ! $rev;
Branch: 1 branch
BranchTrueFalseTotal
unless $rev 4 53 57
379 53 ($fr,$to) = ($to,$fr);
380 } else {
381 510 $rev = 0;
382 }
383  
384 563 my $c = $fr;
385 563 my @retv;
386 563 my $nextchar = $obj->{nextchar};
387 563 while (1) {
388 11948 push @retv, $c;
389 11948 ▶ last if $c eq $to;
Branch: 1 branch
BranchTrueFalseTotal
if $c eq $to 563 11385 11948
390 11385 $c = &$nextchar($c);
391 11385 ▶ croak $Msg_lastc if !defined $c;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 11385 11385
392 }
393 563 ▶ return $rev ? reverse(@retv) : @retv;
Branch: 1 branch
BranchTrueFalseTotal
$rev ? : 53 510 563
394 }
395  
396 #==========
397 # strtr
398 #
399 22 my %Cache;
400  
401 2956 ▶sub strtr {
Subroutine strtr: called CC=9 SCAR=26.9
Pod documented
402 2956 my $obj = shift;
403 my $re = $obj->{regexp}
404 2956 ▶ or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 2956 0 2956
405 2956 my $str = shift;
406  
407 2956 ▶ if ($obj->{verbose} && ! $obj->islegal(ref $str ? $$str : $str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal(ref $str ? $$str : $str)) 0 2956 2956
ref $str ? : 2905 49 2954
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal(ref $str ? $$str : $str)
!ll&&!rl&&r
229540
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal(ref $str ? $$str : $str)
$obj->{"verbose"} not $obj->islegal(ref $str ? $$str : $str)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal(ref $str ? $$str : $str)
ABresult
0X0
100
111
408 0 carp sprintf "$Msg_malfo in strtr", $obj->{charset};
409 }
410 2956 my $coderef;
411 2956 ▶ if (defined $_[2] && $_[2] =~ /o/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[2] and $_[2] =~ /o/) { } 0 2956 2956
Condition66%2/3
defined $_[2] and $_[2] =~ /o/
!ll&&!rl&&r
2629300
MC/DC0%0/2
defined $_[2] and $_[2] =~ /o/
defined $_[2] $_[2] =~ /o/
Truth table66%2/3
A and B
A= defined $_[2]B= $_[2] =~ /o/
ABresult
0X0
100
111
412 $coderef = (
413 $Cache{ $obj->{charset} }{ $_[0] }{ $_[1] }
414 0 ▶ { defined $_[2] ? $_[2] : ''} ||= $obj->trclosure(@_)
Branch: 1 branch
BranchTrueFalseTotal
defined $_[2] ? : 0 0 0
Condition0%0/3
$Cache{$obj->{"charset"}}{$_[0]}{$_[1]}{defined $_[2] ? $_[2] : ""} ||= $obj->trclosure(@_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$Cache{$obj->{"charset"}}{$_[0]}{$_[1]}{defined $_[2] ? $_[2] : ""} ||= $obj->trclosure(@_)
$Cache{$obj->{"charset"}}{$_[0]}{$_[1]}{defined $_[2] ? $_[2] : ""} $obj->trclosure(@_)
Truth table0%0/3
A ||= B
A= $Cache{$obj->{"charset"}}{$_[0]}{$_[1]}{defined $_[2] ? $_[2] : ""}B= $obj->trclosure(@_)
ABresult
1X1
011
000
415 );
416 }
417 else {
418 2956 $coderef = $obj->trclosure(@_);
419 }
420 2956 &$coderef($str);
421 }
422  
423 #============
424 # trclosure
425 #
426 3082 ▶sub trclosure {
Subroutine trclosure: called CC=26 SCAR=34.1
Pod documented
427 3082 my(@fr, @to, $h, $r, $R, $c, $d, $s, $v, $i, %hash);
428 3082 my $obj = shift;
429 3082 ▶ my $re = $obj->{regexp} or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 3082 0 3082
430  
431 3082 my $fr = shift;
432 3082 my $to = shift;
433 3082 ▶ my $mod = @_ ? shift : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2930 152 3082
434  
435 3082 ▶ if ($obj->{verbose} && ! $obj->islegal($fr, $to)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($fr, $to)) 0 3082 3082
Condition66%2/3
$obj->{"verbose"} and not $obj->islegal($fr, $to)
!ll&&!rl&&r
230800
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($fr, $to)
$obj->{"verbose"} not $obj->islegal($fr, $to)
Truth table66%2/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($fr, $to)
ABresult
0X0
100
111
436 0 carp sprintf "$Msg_malfo in trclosure", $obj->{charset};
437 }
438 3082 my $msg = sprintf "$Msg_malfo in closure", $obj->{charset};
439  
440 3082 $h = $mod =~ /h/;
441 3082 $r = $mod =~ /r/;
442 3082 $R = $mod =~ /R/;
443 3082 $v = $obj->{verbose};
444  
445 3082 ▶ for (ref $fr eq 'ARRAY' ? @$fr: $fr) {
Branch: 1 branch
BranchTrueFalseTotal
ref $fr eq 'ARRAY' ? : 5 3077 3082
446 3086 ▶ push @fr, $R ? /\G$re/g : $obj->mkrange($_, $r);
Branch: 1 branch
BranchTrueFalseTotal
$R ? : 15 3071 3086
447 }
448  
449 3082 ▶ for (ref $to eq 'ARRAY' ? @$to : $to) {
Branch: 1 branch
BranchTrueFalseTotal
ref $to eq 'ARRAY' ? : 3 3079 3082
450 3084 ▶ push @to, $R ? /\G$re/g : $obj->mkrange($_, $r);
Branch: 1 branch
BranchTrueFalseTotal
$R ? : 15 3069 3084
451 }
452  
453 3082 $c = $mod =~ /c/;
454 3082 $d = $mod =~ /d/;
455 3082 $s = $mod =~ /s/;
456 3082 $mod = $s * 4 + $d * 2 + $c;
457  
458 3082 ▶ for ($i = 0; $i < @fr; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @fr) 14941 3082 18023
459 14941 ▶ next if exists $hash{ $fr[$i] };
Branch: 1 branch
BranchTrueFalseTotal
if exists $hash{$fr[$i]} 960 13981 14941
460 13981 ▶ $hash{ $fr[$i] } = @to
Branch: 4 branches
BranchTrueFalseTotal
@to ? : 10944 3037 13981
defined $to[$i] ? : 9404 1540 10944
$d ? : 440 1100 1540
$d && !$c ? : 552 2485 3037
Condition100%3/3
$d and not $c
!ll&&!rl&&r
1933552552
MC/DC100%2/2
$d and not $c
$d not $c
Truth table100%3/3
A and not(B)
A= $dB= not $c
ABresult
0X0
100
111
461 ? defined $to[$i] ? $to[$i] : $d ? '' : $to[-1]
462 : $d && !$c ? '' : $fr[$i];
463 }
464 return
465 $mod == 3 || $mod == 7 ?
466 722 ▶ sub { # $c: true, $d: true, $s: true/false, $mod: 3 or 7
Subroutine __ANON__: called CC=10 SCAR=25.3
467 722 my $str = shift;
468 722 ▶ if ($v && !$obj->islegal(ref $str ? $$str : $str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v and not $obj->islegal(ref $str ? $$str : $str)) 0 722 722
ref $str ? : 722 0 722
Condition33%1/3
$v and not $obj->islegal(ref $str ? $$str : $str)
!ll&&!rl&&r
07220
MC/DC0%0/2
$v and not $obj->islegal(ref $str ? $$str : $str)
$v not $obj->islegal(ref $str ? $$str : $str)
Truth table33%1/3
A and not(B)
A= $vB= not $obj->islegal(ref $str ? $$str : $str)
ABresult
0X0
100
111
469 0 carp $msg;
470 }
471 722 my $cnt = 0;
472 722 my %cnt = ();
473 722 ▶ (ref $str ? $$str : $str) =~ s{($re)}{
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 722 0 722
474 23060 ▶ exists $hash{$1} ? $1 : ($h ? ++$cnt{$1} : ++$cnt, '');
Branch: 2 branches
BranchTrueFalseTotal
exists $hash{$1} ? : 4092 18968 23060
$h ? : 8 18960 18968
475 }ge;
476 722 ▶ return $h
Branch: 3 branches
BranchTrueFalseTotal
$h ? : 2 720 722
wantarray ? : 2 0 2
ref $str ? : 720 0 720
477 ? wantarray ? %cnt : \%cnt
478 : ref $str ? $cnt : $str;
479 } :
480 $mod == 5 ?
481 364 ▶ sub { # $c: true, $d: false, $s: true, $mod: 5
Subroutine __ANON__: called CC=12 SCAR=26.4
482 364 my $str = shift;
483 364 ▶ if ($v && !$obj->islegal(ref $str ? $$str : $str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v and not $obj->islegal(ref $str ? $$str : $str)) 0 364 364
ref $str ? : 360 4 364
Condition33%1/3
$v and not $obj->islegal(ref $str ? $$str : $str)
!ll&&!rl&&r
03640
MC/DC0%0/2
$v and not $obj->islegal(ref $str ? $$str : $str)
$v not $obj->islegal(ref $str ? $$str : $str)
Truth table33%1/3
A and not(B)
A= $vB= not $obj->islegal(ref $str ? $$str : $str)
ABresult
0X0
100
111
484 0 carp $msg;
485 }
486 364 my $cnt = 0;
487 364 my %cnt = ();
488 364 my $pre = '';
489 364 my $now;
490 364 ▶ (ref $str ? $$str : $str) =~ s{($re)}{
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 360 4 364
491 exists $hash{$1}
492 ? ($pre = '', $1)
493 11580 ▶ : ($h ? ++$cnt{$1} : ++$cnt,
Branch: 4 branches
BranchTrueFalseTotal
exists $hash{$1} ? : 2068 9512 11580
$h ? : 0 9512 9512
@to ? : 7932 1580 9512
$now eq $pre ? : 6320 3192 9512
494 $now = @to ? $to[-1] : $1,
495 $now eq $pre ? '' : ($pre = $now) );
496 }ge;
497 364 ▶ return $h
Branch: 3 branches
BranchTrueFalseTotal
$h ? : 0 364 364
wantarray ? : 0 0 0
ref $str ? : 360 4 364
498 ? wantarray ? %cnt : \%cnt
499 : ref $str ? $cnt : $str;
500 } :
501 $mod == 4 || $mod == 6 ?
502 724 ▶ sub { # $c: false, $d: true/false, $s: true, $mod: 4 or 6
Subroutine __ANON__: called CC=12 SCAR=26.4
503 724 my $str = shift;
504 724 ▶ if ($v && !$obj->islegal(ref $str ? $$str : $str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v and not $obj->islegal(ref $str ? $$str : $str)) 0 724 724
ref $str ? : 720 4 724
Condition33%1/3
$v and not $obj->islegal(ref $str ? $$str : $str)
!ll&&!rl&&r
07240
MC/DC0%0/2
$v and not $obj->islegal(ref $str ? $$str : $str)
$v not $obj->islegal(ref $str ? $$str : $str)
Truth table33%1/3
A and not(B)
A= $vB= not $obj->islegal(ref $str ? $$str : $str)
ABresult
0X0
100
111
505 0 carp $msg;
506 }
507 724 my $cnt = 0;
508 724 my %cnt = ();
509 724 my $pre = '';
510 724 ▶ (ref $str ? $$str : $str) =~ s{($re)}{
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 720 4 724
511 exists $hash{$1}
512 ? ($h ? ++$cnt{$1} : ++$cnt,
513 $hash{$1} eq '' || $hash{$1} eq $pre
514 23092 ▶ ? '' : ($pre = $hash{$1}))
Branch: 3 branches
BranchTrueFalseTotal
exists $hash{$1} ? : 4128 18964 23092
$h ? : 0 4128 4128
$hash{$1} eq '' || $hash{$1} eq $pre ? : 842 3286 4128
Condition100%3/3
$hash{$1} eq "" or $hash{$1} eq $pre
l!l&&r!l&&!r
6102323286
MC/DC100%2/2
$hash{$1} eq "" or $hash{$1} eq $pre
$hash{$1} eq "" $hash{$1} eq $pre
Truth table100%3/3
A or B
A= $hash{$1} eq ""B= $hash{$1} eq $pre
ABresult
1X1
011
000
515 : ($pre = '', $1);
516 }ge;
517 724 ▶ return $h
Branch: 3 branches
BranchTrueFalseTotal
$h ? : 0 724 724
wantarray ? : 0 0 0
ref $str ? : 720 4 724
518 ? wantarray ? %cnt : \%cnt
519 : ref $str ? $cnt : $str;
520 } :
521 $mod == 1 ?
522 364 ▶ sub { # $c: true, $d: false, $s: false, $mod: 1
Subroutine __ANON__: called CC=11 SCAR=26.1
523 364 my $str = shift;
524 364 ▶ if ($v && !$obj->islegal(ref $str ? $$str : $str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v and not $obj->islegal(ref $str ? $$str : $str)) 0 364 364
ref $str ? : 364 0 364
Condition33%1/3
$v and not $obj->islegal(ref $str ? $$str : $str)
!ll&&!rl&&r
03640
MC/DC0%0/2
$v and not $obj->islegal(ref $str ? $$str : $str)
$v not $obj->islegal(ref $str ? $$str : $str)
Truth table33%1/3
A and not(B)
A= $vB= not $obj->islegal(ref $str ? $$str : $str)
ABresult
0X0
100
111
525 0 carp $msg;
526 }
527 364 my $cnt = 0;
528 364 my %cnt = ();
529 364 ▶ (ref $str ? $$str : $str) =~ s{($re)}{
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 364 0 364
530 exists $hash{$1}
531 ? $1
532 11566 ▶ : ($h ? ++$cnt{$1} : ++$cnt, @to) ? $to[-1] : $1;
Branch: 3 branches
BranchTrueFalseTotal
exists $hash{$1} ? : 2066 9500 11566
($h ? ++$cnt{$1} : ++$cnt, @to) ? : 7912 1588 9500
$h ? : 20 9480 9500
533 }ge;
534 364 ▶ return $h
Branch: 3 branches
BranchTrueFalseTotal
$h ? : 4 360 364
wantarray ? : 4 0 4
ref $str ? : 360 0 360
535 ? wantarray ? %cnt : \%cnt
536 : ref $str ? $cnt : $str;
537 } :
538 $mod == 0 || $mod == 2 ?
539 17564 ▶ sub { # $c: false, $d: true/false, $s: false, $mod: 0 or 2
Subroutine __ANON__: called CC=10 SCAR=23.2
540 17564 my $str = shift;
541 17564 ▶ if ($v && !$obj->islegal(ref $str ? $$str : $str)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v and not $obj->islegal(ref $str ? $$str : $str)) 0 17564 17564
ref $str ? : 739 16823 17562
Condition66%2/3
$v and not $obj->islegal(ref $str ? $$str : $str)
!ll&&!rl&&r
2175620
MC/DC0%0/2
$v and not $obj->islegal(ref $str ? $$str : $str)
$v not $obj->islegal(ref $str ? $$str : $str)
Truth table66%2/3
A and not(B)
A= $vB= not $obj->islegal(ref $str ? $$str : $str)
ABresult
0X0
100
111
542 0 carp $msg;
543 }
544 17564 my $cnt = 0;
545 17564 my %cnt = ();
546 17564 ▶ (ref $str ? $$str : $str) =~ s{($re)}{
Branch: 1 branch
BranchTrueFalseTotal
ref $str ? : 739 16825 17564
547 exists $hash{$1}
548 128087 ▶ ? ($h ? ++$cnt{$1} : ++$cnt, $hash{$1})
Branch: 2 branches
BranchTrueFalseTotal
exists $hash{$1} ? : 62004 66083 128087
$h ? : 164 61840 62004
549 : $1;
550 }ge;
551 17564 ▶ return $h
Branch: 3 branches
BranchTrueFalseTotal
$h ? : 21 17543 17564
wantarray ? : 19 2 21
ref $str ? : 735 16808 17543
552 ? wantarray ? %cnt : \%cnt
553 : ref $str ? $cnt : $str;
554 } :
555 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
556 0 croak sprintf $Msg_panic, "trclosure! Invalid Closure!";
557 }
558 3082 ▶}
Branch: 5 branches
BranchTrueFalseTotal
$mod == 3 || $mod == 7 ? : 722 2360 3082
$mod == 5 ? : 364 1996 2360
$mod == 4 || $mod == 6 ? : 724 1272 1996
$mod == 1 ? : 364 908 1272
$mod == 0 || $mod == 2 ? : 908 0 908
Condition88%8/9
$mod == 3 or $mod == 7
l!l&&r!l&&!r
3623602360
$mod == 4 or $mod == 6
l!l&&r!l&&!r
3643601272
$mod == 0 or $mod == 2
l!l&&r!l&&!r
5463620
MC/DC100%2/2
$mod == 3 or $mod == 7
$mod == 3 $mod == 7
MC/DC100%2/2
$mod == 4 or $mod == 6
$mod == 4 $mod == 6
MC/DC0%0/2
$mod == 0 or $mod == 2
$mod == 0 $mod == 2
Truth table100%3/3
A or B
A= $mod == 3B= $mod == 7
ABresult
1X1
011
000
Truth table100%3/3
A or B
A= $mod == 4B= $mod == 6
ABresult
1X1
011
000
Truth table66%2/3
A or B
A= $mod == 0B= $mod == 2
ABresult
1X1
011
000
559  
560 #============
561 # strsplit
562 #
563 1097 ▶sub strsplit {
Subroutine strsplit: called CC=31 SCAR=35.4
Pod documented
564 1097 my $obj = shift;
565 1097 ▶ my $re = $obj->{regexp} or croak sprintf $Msg_undef, "regexp";
Branch: 1 branch
BranchTrueFalseTotal
my $re = $obj->{"regexp"} or croak(sprintf($Msg_undef, "regexp")) 1097 0 1097
566 1097 my $sub = shift;
567 1097 my $str = shift;
568 1097 ▶ my $lim = shift || 0;
Condition100%2/2
shift() || 0
l!l
102374
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
569  
570 1097 ▶ if ($obj->{verbose} && ! $obj->islegal($str, $sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{"verbose"} and not $obj->islegal($str, $sub)) 0 1097 1097
Condition33%1/3
$obj->{"verbose"} and not $obj->islegal($str, $sub)
!ll&&!rl&&r
010970
MC/DC0%0/2
$obj->{"verbose"} and not $obj->islegal($str, $sub)
$obj->{"verbose"} not $obj->islegal($str, $sub)
Truth table33%1/3
A and not(B)
A= $obj->{"verbose"}B= not $obj->islegal($str, $sub)
ABresult
0X0
100
111
571 0 carp sprintf $Msg_malfo, $obj->{charset};
572 }
573 1097 ▶ if ($str eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq "") 510 587 1097
574 510 ▶ return wantarray ? () : 0;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 290 220 510
575 }
576 587 ▶ if ($sub eq '' && $lim <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sub eq "" and $lim <= 0) 40 547 587
Condition100%3/3
$sub eq "" and $lim <= 0
!ll&&!rl&&r
14740040
MC/DC100%2/2
$sub eq "" and $lim <= 0
$sub eq "" $lim <= 0
Truth table100%3/3
A and B
A= $sub eq ""B= $lim <= 0
ABresult
0X0
100
111
577 return wantarray
578 40 ▶ ? ($str =~ /$re/g, $lim < 0 ? '' : ())
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 20 20 40
$lim < 0 ? : 10 10 20
579 : ($lim < 0) + $obj->length($str);
580 }
581 547 ▶ if ($lim == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lim == 1) 41 506 547
582 41 ▶ return wantarray ? ($str) : 1;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 21 20 41
583 }
584  
585 506 my $cnt = 0;
586 506 ▶ my @ret = CORE::length($sub) ? ('') : ();
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $sub ? : 126 380 506
587  
588 506 ▶ if (CORE::length($sub)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::length $sub) { } 126 380 506
589 126 my $pat = quotemeta $sub;
590 126 my $sublen = __strlen($re, $sub);
591  
592 126 ▶ while(($lim <= 0 || $cnt < $lim) && CORE::length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lim <= 0 || $cnt < $lim and CORE::length $str) 1379 126 1505
Condition100%6/6
$lim <= 0 || $cnt < $lim and CORE::length $str
!ll&&!rl&&r
82441379
$lim <= 0 or $cnt < $lim
l!l&&r!l&&!r
104637782
MC/DC100%3/3
$lim <= 0 || $cnt < $lim and CORE::length $str
$lim <= 0 $cnt < $lim CORE::length $str
Truth table80%4/5
A or B and C
A= $lim <= 0B= $cnt < $limC= CORE::length $str
ABCresult
00X0
1X00
0100
1X11
0111
593 1379 ▶ if ($str =~ /^$pat/ && _check_n($re, $str, $sub, $sublen)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)) { } 652 727 1379
elsif ($str =~ s/^($re)//) { } 727 0 727
Condition100%3/3
$str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)
!ll&&!rl&&r
68938652
MC/DC100%2/2
$str =~ /^$pat/ and _check_n($re, $str, $sub, $sublen)
$str =~ /^$pat/ _check_n($re, $str, $sub, $sublen)
Truth table100%3/3
A and B
A= $str =~ /^$pat/B= _check_n($re, $str, $sub, $sublen)
ABresult
0X0
100
111
594 652 ▶ $str =~ s/^$pat//
Branch: 2 branches
BranchTrueFalseTotal
$str =~ s/^$pat// or croak(sprintf($Msg_panic, "strsplit"), unpack("H*", CORE::length $str > 15 ? substr($str, 0, 15) : $str)) 652 0 652
CORE::length $str > 15 ? : 0 0 0
595 or croak sprintf($Msg_panic, "strsplit"),
596 unpack('H*', CORE::length($str) > 15
597 ? CORE::substr($str, 0, 15) : $str);
598 652 $cnt = push @ret, '';
599 } elsif ($str =~ s/^($re)//) {
600 727 $ret[-1] .= $1;
601 } else {
602 0 ▶ croak sprintf($Msg_panic, "strsplit").
Branch: 1 branch
BranchTrueFalseTotal
CORE::length $str > 10 ? : 0 0 0
603 unpack('H*', CORE::length($str) > 10
604 ? CORE::substr($str, 0, 10) : $str);
605 }
606 }
607 } else {
608 380 ▶ while ($cnt < $lim && CORE::length($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt < $lim and CORE::length $str) 4180 380 4560
Condition66%2/3
$cnt < $lim and CORE::length $str
!ll&&!rl&&r
38004180
MC/DC50%1/2
$cnt < $lim and CORE::length $str
$cnt < $lim CORE::length $str
Truth table66%2/3
A and B
A= $cnt < $limB= CORE::length $str
ABresult
0X0
100
111
609 4180 ▶ $str =~ s/^($re)//
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/^($re)// or croak(sprintf($Msg_panic, "strsplit ''")) 4180 0 4180
610 or croak sprintf $Msg_panic, "strsplit ''";
611 4180 $cnt = push @ret, $1;
612 }
613 }
614 506 ▶ $ret[-1] .= $str if CORE::length($str);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $str 462 44 506
615 506 ▶ if ($lim == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lim == 0) 24 482 506
616 pop @ret
617 24 ▶ while defined $ret[-1] && $ret[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
defined $ret[-1] and $ret[-1] eq "" and do { pop @ret } 20 24 44
Condition66%2/3
defined $ret[-1] and $ret[-1] eq ""
!ll&&!rl&&r
02420
MC/DC50%1/2
defined $ret[-1] and $ret[-1] eq ""
defined $ret[-1] $ret[-1] eq ""
Truth table66%2/3
A and B
A= defined $ret[-1]B= $ret[-1] eq ""
ABresult
0X0
100
111
618 }
619 506 return @ret;
620 }
621  
622 22 1;
623 __END__
« Multibyte/UTF8.pm ↑ Summary Multibyte/EUC_JP.pm »