Regexp.pm

filter: Statementstmt 82.2% 209 / 254 Branchbran 77.5% 135 / 174 Conditioncond 77.7% 35 / 45 MC/DCmcdc 62.9% 17 / 27 Subroutinesub 92.8% 13 / 14 Podpod 75.0% 6 / 8 totaltotal 79.5% 415 / 522 CC 107 SCAR 37.6
CC
107
Cov
80%
re
86.1
jsplit
22.9
dst
18.5
CRAP 42.9
« Regexp/Class.pm ↑ Summary Regexp/Equiv.pm »
1 package ShiftJIS::Regexp;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use vars qw($VERSION $PACKAGE @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 $VERSION = '1.03';
8 6 $PACKAGE = 'ShiftJIS::Regexp'; #__PACKAGE__
9  
10 6 ▶use vars qw(%Err %Re $Char $PadA $PadG $PadGA);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use ShiftJIS::Regexp::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use ShiftJIS::Regexp::Const qw(%Err %Re $Char $PadA $PadG $PadGA);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 require Exporter;
15 6 @ISA = qw(Exporter);
16  
17 6 %EXPORT_TAGS = (
18 're' => [qw(re mkclass rechar)],
19 'op' => [qw(match replace)],
20 'split' => [qw(jsplit splitchar splitspace)],
21 );
22 6 $EXPORT_TAGS{all} = [ map @$_, values %EXPORT_TAGS ];
23 6 @EXPORT_OK = @{ $EXPORT_TAGS{all} };
24 6 @EXPORT = ();
25  
26 6 my(%Cache);
27  
28 0 ▶sub getReCache { wantarray ? %Cache : \%Cache }
Subroutine getReCache: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
29  
30 1353 ▶sub re ($;$) {
Subroutine re: called CC=48 SCAR=44.6
Pod documented
31 1353 my($flag);
32 1353 my $pat = shift;
33 1353 ▶ my $mod = shift || '';
Condition100%2/2
shift() || ''
l!l
721281
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
34 1353 ▶ if ($pat =~ s/^ (\^|\\[AG]|) \(\? ([a-zA-Z]+) \) /$1/x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ s/^ (\^|\\[AG]|) \(\? ([a-zA-Z]+) \) /$1/x) 51 1302 1353
35 51 $mod .= $2;
36 }
37  
38 1353 my $s = $mod =~ /s/;
39 1353 my $m = $mod =~ /m/;
40 1353 my $x = $mod =~ /x/;
41 1353 my $h = $mod =~ /h/;
42  
43 1353 ▶ if ($mod =~ /o/ && defined $Cache{$pat}{$mod}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /o/ and defined $Cache{$pat}{$mod}) 19 1334 1353
Condition100%3/3
$mod =~ /o/ and defined $Cache{$pat}{$mod}
!ll&&!rl&&r
1333119
MC/DC100%2/2
$mod =~ /o/ and defined $Cache{$pat}{$mod}
$mod =~ /o/ defined $Cache{$pat}{$mod}
Truth table100%3/3
A and B
A= $mod =~ /o/B= defined $Cache{$pat}{$mod}
ABresult
0X0
100
111
44 19 return $Cache{$pat}{$mod};
45 }
46  
47 1334 ▶ my $res = $m && $s ? '(?ms)' : $m ? '(?m)' : $s ? '(?s)' : '';
Branch: 3 branches
BranchTrueFalseTotal
$m && $s ? : 0 1334 1334
$m ? : 5 1329 1334
$s ? : 2 1327 1329
Condition66%2/3
$m and $s
!ll&&!rl&&r
132950
MC/DC0%0/2
$m and $s
$m $s
Truth table66%2/3
A and B
A= $mB= $s
ABresult
0X0
100
111
48 1334 my $tmppat = $pat;
49  
50 1334 for ($tmppat) {
51 1334 ▶ while (length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_) 2378 1334 3712
52 2378 ▶ if (s/^(\(\?[p?]?\{)//) { # (?{}), (??{}) and (?p{})
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(\(\?[p?]?\{)//) 0 2378 2378
53 0 $res .= $1;
54 0 my $count = 1;
55 0 ▶ while ($count && length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count and length $_) 0 0 0
Condition0%0/3
$count and length $_
!ll&&!rl&&r
000
MC/DC0%0/2
$count and length $_
$count length $_
Truth table0%0/3
A and B
A= $countB= length $_
ABresult
0X0
100
111
56 0 ▶ if (s/^(\x5C[\x00-\xFC])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(\x5C[\x00-\xFC])//) 0 0 0
57 0 $res .= $1;
58 0 next;
59 }
60 0 ▶ if (s/^([^\{\}\\]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^([^\{\}\\]+)//) 0 0 0
61 0 $res .= $1;
62 0 next;
63 }
64 0 ▶ if (s/^\{//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\{//) 0 0 0
65 0 ++$count;
66 0 $res .= '{';
67 0 next;
68 }
69 0 ▶ if (s/^\}//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\}//) 0 0 0
70 0 --$count;
71 0 $res .= '}';
72 0 next;
73 }
74 0 croak $Err{Code};
75 }
76 0 ▶ if (s/^\)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\)//) 0 0 0
77 0 $res .= ')';
78 0 next;
79 }
80 0 croak $Err{Code};
81 }
82  
83 2378 ▶ if (s/^\x5B(\^?)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\x5B(\^?)//) 874 1504 2378
84 874 my $not = $1;
85 874 my $class = parse_class(\$_, $mod);
86 874 ▶ $res .= $not ? "(?:(?!$class)$Char)" : $class;
Branch: 1 branch
BranchTrueFalseTotal
$not ? : 103 771 874
87 874 next;
88 }
89  
90 1504 ▶ if (s/^\\([.*+?^$|\\()\[\]\{\}])//) { # backslashed meta chars
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([.*+?^$|\\()\[\]\{\}])//) 4 1500 1504
91 4 $res .= '\\'.$1;
92 4 next;
93 }
94 1500 ▶ if (s|^\\?(['"/])||) { # <'>, <">, </> should be backslashed.
Branch: 1 branch
BranchTrueFalseTotal
if (s[^\\?(['"/])][]) 0 1500 1500
95 0 $res .= '\\'.$1;
96 0 next;
97 }
98 1500 ▶ if ($x && s/^\s+//) { # skip whitespace
Branch: 1 branch
BranchTrueFalseTotal
if ($x and s/^\s+//) 11 1489 1500
Condition100%3/3
$x and s/^\s+//
!ll&&!rl&&r
14682111
MC/DC100%2/2
$x and s/^\s+//
$x s/^\s+//
Truth table100%3/3
A and B
A= $xB= s/^\s+//
ABresult
0X0
100
111
99 11 next;
100 }
101 1489 ▶ if (s/^\.//) { # dot
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\.//) 5 1484 1489
102 5 ▶ $res .= $s ? $Re{'\j'} : $Re{'\J'};
Branch: 1 branch
BranchTrueFalseTotal
$s ? : 0 5 5
103 5 next;
104 }
105 1484 ▶ if (s/^\^//) { # begin
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\^//) 598 886 1484
106 598 $res .= '(?:^)';
107 598 next;
108 }
109 886 ▶ if (s/^\$//) { # end
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\$//) 37 849 886
110 37 $res .= '(?:$)';
111 37 next;
112 }
113 849 ▶ if (s/^\\z//) { # \z (Perl 5.003 doesn't have this)
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\z//) 8 841 849
114 8 $res .= '(?!\n)\Z';
115 8 next;
116 }
117 841 ▶ if (s/^\\([dDwWsSCjJ])//) { # class
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([dDwWsSCjJ])//) 46 795 841
118 46 $res .= $Re{ "\\$1" };
119 46 next;
120 }
121 795 ▶ if (s/^\\([pP])//) { # prop
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([pP])//) 227 568 795
122 227 my $key = parse_prop($1, \$_);
123 227 ▶ if (defined $Re{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ShiftJIS::Regexp::Re{$key}) { } 227 0 227
124 227 $res .= $Re{$key};
125 } else {
126 0 croak sprintf($Err{Undef}, $key);
127 }
128 227 next;
129 }
130 568 ▶ if (s/^\\([R])//) { # regex
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([R])//) 1 567 568
131 1 my $key = parse_regex($1, \$_);
132 1 ▶ if (defined $Re{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ShiftJIS::Regexp::Re{$key}) { } 1 0 1
133 1 $res .= $Re{$key};
134 } else {
135 0 croak sprintf($Err{Undef}, $key);
136 }
137 1 next;
138 }
139 567 ▶ if (s/^\\([0-7][0-7][0-7]?)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([0-7][0-7][0-7]?)//) 1 566 567
140 1 $res .= rechar(chr oct $1, $mod);
141 1 next;
142 }
143 566 ▶ if (s/^\\0//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\0//) 3 563 566
144 3 $res .='\\x00';
145 3 next;
146 }
147 563 ▶ if (s/^\\c([\x00-\x7F])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\c([\x00-\x7F])//) 72 491 563
148 72 $res .= rechar(chr(ord(uc $1) ^ 64), $mod);
149 72 next;
150 }
151 491 ▶ if (s/^\\x([0-9A-Fa-f][0-9A-Fa-f])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\x([0-9A-Fa-f][0-9A-Fa-f])//) 1 490 491
152 1 $res .= rechar(chr hex $1, $mod);
153 1 next;
154 }
155 490 ▶ if (s/^\\x\{([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])\}//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\x\{([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])\}//) 2 488 490
156 2 $res .= rechar(chr(hex $1).chr(hex $2), $mod);
157 2 next;
158 }
159 488 ▶ if (s/^\\([A-Za-z])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([A-Za-z])//) 9 479 488
160 9 $res .= '\\'. $1;
161 9 next;
162 }
163 479 ▶ if (s/^(\(\?[a-z\-\s]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^(\(\?[a-z\-\s]+)//) 2 477 479
164 2 $res .= $1;
165 2 next;
166 }
167 477 ▶ if (s/^\\([1-9])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([1-9])//) 1 476 477
168 1 ▶ $res .= $h ? '\\'. ($1+1) : '\\'. $1;
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 0 1 1
169 1 next;
170 }
171 476 ▶ if (s/^([\x21-\x40\x5B\x5D-\x60\x7B-\x7E])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^([\x21-\x40\x5B\x5D-\x60\x7B-\x7E])//) 306 170 476
172 306 $res .= $1;
173 306 next;
174 }
175 170 ▶ if ($_ eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "\\") 0 170 170
176 0 croak $Err{backtips};
177 }
178 170 ▶ if (s/^\\?($Char)//o) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\?($ShiftJIS::Regexp::Char)//o) 170 0 170
179 170 $res .= rechar($1, $mod);
180 170 next;
181 }
182 0 croak sprintf($Err{oddTrail}, ord);
183 }
184 }
185 1334 ▶ return $mod =~ /o/ ? ($Cache{$pat}{$mod} = $res) : $res;
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ /o/ ? : 1 1333 1334
186 }
187  
188  
189  
190 48 ▶sub dst ($) {
Subroutine dst: called CC=15 SCAR=29.2
Pod undocumented
191 48 my $str = shift;
192 48 my $res = '';
193 48 for ($str) {
194 48 ▶ while (length) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_) 76 48 124
195 76 ▶ if (s/^\\\\//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\\\//) 1 75 76
196 1 $res .= '\\\\';
197 1 next;
198 }
199 75 ▶ if (s/^\\?\///) {
Branch: 1 branch
BranchTrueFalseTotal
if (s[^\\?/][]) 0 75 75
200 0 $res .= '\\/';
201 0 next;
202 }
203 75 ▶ if (s/^\$([1-8])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\$([1-8])//) 24 51 75
204 24 $res .= '${' . ($1 + 1) . '}';
205 24 next;
206 }
207 51 ▶ if (s/^\$\{([1-8])\}//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\$\{([1-8])\}//) 4 47 51
208 4 $res .= '${' . ($1 + 1) . '}';
209 4 next;
210 }
211 47 ▶ if (s/^\\([0-7][0-7][0-7])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([0-7][0-7][0-7])//) 0 47 47
212 0 $res .= "\\$1";
213 0 next;
214 }
215 47 ▶ if (s/^\\([0-7][0-7])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([0-7][0-7])//) 0 47 47
216 0 $res .= "\\0$1";
217 0 next;
218 }
219 47 ▶ if (s/^\\x([0-9A-Fa-f][0-9A-Fa-f])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\x([0-9A-Fa-f][0-9A-Fa-f])//) 0 47 47
220 0 $res .= "\\x$1";
221 0 next;
222 }
223 47 ▶ if (s/^\\x\{([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])\}//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\x\{([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])\}//) 2 45 47
224 2 $res .= '\\x' . $1 . '\\x' . $2;
225 2 next;
226 }
227 45 ▶ if (s/^\\0//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\0//) 0 45 45
228 0 $res .='\\x00';
229 0 next;
230 }
231 45 ▶ if (s/^\\([A-Za-z])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\([A-Za-z])//) 1 44 45
232 1 $res .= '\\'. $1;
233 1 next;
234 }
235 44 ▶ if (s/^\\?([\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\?([\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC])//) 15 29 44
236 15 $res .= quotemeta($1);
237 15 next;
238 }
239 29 ▶ if (s/^\\?([\x00-\x7F\xA1-\xDF])//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^\\?([\x00-\x7F\xA1-\xDF])//) 29 0 29
240 29 $res .= $1;
241 29 next;
242 }
243 0 croak sprintf($Err{oddTrail}, ord);
244 }
245 }
246 48 return $res;
247 }
248  
249 98 ▶sub match ($$;$) {
Subroutine match: called CC=5 SCAR=20.9
Pod documented
250 98 my $str = $_[0];
251 98 ▶ my $mod = $_[2] || '';
Condition100%2/2
$_[2] || ''
l!l
2276
MC/DC100%1/1
$_[2] || ''
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
252 98 my $pat = re($_[1], $mod);
253 98 ▶ if ($mod =~ /g/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /g/) { } 0 98 98
254 0 ▶ my $fore = $mod =~ /z/ || '' =~ /$pat/ ? $PadGA : $PadG;
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ /z/ || '' =~ /$pat/ ? : 0 0 0
Condition0%0/3
$mod =~ /z/ or "" =~ /$pat/
l!l&&r!l&&!r
000
MC/DC0%0/2
$mod =~ /z/ or "" =~ /$pat/
$mod =~ /z/ "" =~ /$pat/
Truth table0%0/3
A or B
A= $mod =~ /z/B= "" =~ /$pat/
ABresult
1X1
011
000
255 0 $str =~ /$fore(?:$pat)/g;
256 } else {
257 98 $str =~ /$PadA(?:$pat)/;
258 }
259 }
260  
261  
262 48 ▶sub replace ($$$;$) {
Subroutine replace: called CC=7 SCAR=19.5
Pod documented
263 48 my $str = $_[0];
264 48 my $dst = dst($_[2]);
265 48 ▶ my $mod = $_[3] || '';
Condition100%2/2
$_[3] || ''
l!l
3414
MC/DC100%1/1
$_[3] || ''
$_[3]
Truth table100%2/2
A
A= $_[3]
Aresult
11
00
266 48 my $pat = re($_[1], 'h'.$mod);
267 48 ▶ if ($mod =~ /g/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod =~ /g/) { } 32 16 48
268 32 ▶ my $fore = $mod =~ /z/ || '' =~ /$pat/ ? $PadGA : $PadG;
Branch: 1 branch
BranchTrueFalseTotal
$mod =~ /z/ || '' =~ /$pat/ ? : 3 29 32
Condition100%3/3
$mod =~ /z/ or "" =~ /$pat/
l!l&&r!l&&!r
1229
MC/DC100%2/2
$mod =~ /z/ or "" =~ /$pat/
$mod =~ /z/ "" =~ /$pat/
Truth table100%3/3
A or B
A= $mod =~ /z/B= "" =~ /$pat/
ABresult
1X1
011
000
269 32 ▶ if (ref $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $str) { } 0 32 32
270 0 eval "\$\$str =~ s/($fore)(?:$pat)/\${1}$dst/g";
271 } else {
272 32 eval "\$str =~ s/($fore)(?:$pat)/\${1}$dst/g";
273 32 $str;
274 }
275 } else {
276 16 ▶ if (ref $str) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $str) { } 12 4 16
277 12 eval "\$\$str =~ s/($PadA)(?:$pat)/\${1}$dst/";
278 } else {
279 4 eval "\$str =~ s/($PadA)(?:$pat)/\${1}$dst/";
280 4 $str;
281 }
282 }
283 }
284  
285  
286 #
287 # splitchar(STRING; LIMIT)
288 #
289 176 ▶sub splitchar ($;$) {
Subroutine splitchar: called CC=10 SCAR=23.0
Pod documented
290 176 my $str = shift;
291 176 ▶ my $lim = shift || 0;
Condition100%2/2
shift() || 0
l!l
1688
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
292  
293 176 ▶ return wantarray ? () : 0 if $str eq '';
Branch: 2 branches
BranchTrueFalseTotal
if $str eq "" 88 88 176
wantarray ? : 44 44 88
294 88 ▶ return wantarray ? ($str) : 1 if $lim == 1;
Branch: 2 branches
BranchTrueFalseTotal
if $lim == 1 4 84 88
wantarray ? : 2 2 4
295  
296 84 my(@ret);
297 84 ▶ if ($lim > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lim > 1) { } 76 8 84
298 76 ▶ while ($str =~ s/($Char)//o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/($ShiftJIS::Regexp::Char)//o) 760 0 760
299 760 push @ret, $1;
300 760 ▶ last if @ret >= $lim - 1;
Branch: 1 branch
BranchTrueFalseTotal
if @ret >= $lim - 1 76 684 760
301 }
302 76 push @ret, $str;
303 } else {
304 8 @ret = $str =~ /$Char/go;
305 8 ▶ push @ret, '' if $lim < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $lim < 0 4 4 8
306 }
307 84 return @ret;
308 }
309  
310 #
311 # splitspace(STRING; LIMIT)
312 #
313 47 ▶sub splitspace ($;$) {
Subroutine splitspace: called CC=5 SCAR=16.1
Pod documented
314 47 my $str = shift;
315 47 ▶ my $lim = shift || 0;
Condition100%2/2
shift() || 0
l!l
3611
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
316 47 ▶ return wantarray ? () : 0 if $str eq '';
Branch: 2 branches
BranchTrueFalseTotal
if $str eq "" 14 33 47
wantarray ? : 14 0 14
317  
318 33 my @ret;
319 33 ▶ if (0 < $lim) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < $lim) { } 20 13 33
320 20 $str =~ s/^(?:[ \n\r\t\f]|\x81\x40)+//;
321 20 @ret = jsplit('(?o)[ \n\r\t\f\x{8140}]+', $str, $lim)
322 } else {
323 13 $str =~ s/\G($Char*?)\x81\x40/$1 /go;
324 13 @ret = split(' ', $str, $lim);
325 }
326 33 return @ret;
327 }
328  
329 #
330 # jsplit(PATTERN, STRING; LIMIT)
331 #
332 168 ▶sub jsplit ($$;$) {
Subroutine jsplit: called CC=22 SCAR=31.3
Pod documented
333 168 my $thing = shift;
334 168 my $str = shift;
335 168 ▶ my $lim = shift || 0;
Condition100%2/2
shift() || 0
l!l
14820
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
336  
337 168 ▶ return splitspace($str, $lim) if !defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 23 145 168
338  
339 145 ▶ my $pat = 'ARRAY' eq ref $thing
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq ref $thing ? : 2 143 145
340 ? re($$thing[0], $$thing[1])
341 : re($thing);
342  
343 145 ▶ return splitchar($str, $lim) if $pat eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $pat eq "" 88 57 145
344 57 ▶ return wantarray ? () : 0 if $str eq '';
Branch: 2 branches
BranchTrueFalseTotal
if $str eq "" 7 50 57
wantarray ? : 7 0 7
345 50 ▶ return wantarray ? ($str) : 1 if $lim == 1;
Branch: 2 branches
BranchTrueFalseTotal
if $lim == 1 7 43 50
wantarray ? : 7 0 7
346  
347 43 my $cnt = 0;
348 43 my(@mat, @ret);
349 43 ▶ while (@mat = $str =~ /^($Char*?)($pat)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@mat = $str =~ /^($ShiftJIS::Regexp::Char*?)($pat)/) 136 7 143
350 136 ▶ if ($mat[0] eq '' && $mat[1] eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mat[0] eq '' and $mat[1] eq '') { } 0 136 136
Condition66%2/3
$mat[0] eq "" and $mat[1] eq ""
!ll&&!rl&&r
97390
MC/DC0%0/2
$mat[0] eq "" and $mat[1] eq ""
$mat[0] eq "" $mat[1] eq ""
Truth table66%2/3
A and B
A= $mat[0] eq ""B= $mat[1] eq ""
ABresult
0X0
100
111
351 0 @mat = $str =~ /^($Char)($pat)/;
352 0 $str =~ s/^$Char$pat//;
353 } else {
354 136 $str =~ s/^$Char*?$pat//;
355 }
356 136 ▶ if (@mat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@mat) 136 0 136
357 136 push @ret, shift @mat;
358 136 shift @mat; # $mat[1] eq $2 is to be removed.
359 136 push @ret, @mat;
360 }
361 136 $cnt++;
362 136 ▶ last if ! CORE::length $str;
Branch: 1 branch
BranchTrueFalseTotal
unless length $str 6 130 136
363 130 ▶ last if $lim > 1 && $cnt >= $lim - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $lim > 1 and $cnt >= $lim - 1 30 100 130
Condition100%3/3
$lim > 1 and $cnt >= $lim - 1
!ll&&!rl&&r
564430
MC/DC100%2/2
$lim > 1 and $cnt >= $lim - 1
$lim > 1 $cnt >= $lim - 1
Truth table100%3/3
A and B
A= $lim > 1B= $cnt >= $lim - 1
ABresult
0X0
100
111
364 }
365 43 ▶ push @ret, $str if $str ne '' || $lim < 0 || $cnt < $lim;
Branch: 1 branch
BranchTrueFalseTotal
if $str ne "" or $lim < 0 or $cnt < $lim 40 3 43
Condition83%5/6
$str ne "" or $lim < 0 or $cnt < $lim
l!l&&r!l&&!r
4003
$str ne "" or $lim < 0
l!l&&r!l&&!r
3733
MC/DC66%2/3
$str ne "" or $lim < 0 or $cnt < $lim
$str ne "" $lim < 0 $cnt < $lim
Truth table75%3/4
A or B or C
A= $str ne ""B= $lim < 0C= $cnt < $lim
ABCresult
1XX1
01X1
0011
0000
366 43 ▶ if ($lim == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lim == 0) 10 33 43
367 10 ▶ pop @ret while defined $ret[-1] && $ret[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
defined $ret[-1] and $ret[-1] eq "" and do { pop @ret } 2 10 12
Condition66%2/3
defined $ret[-1] and $ret[-1] eq ""
!ll&&!rl&&r
0102
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
368 }
369 43 return @ret;
370 }
371  
372 6 1;
373 __END__
« Regexp/Class.pm ↑ Summary Regexp/Equiv.pm »