| 1 | package Skilletor::JSString; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: String operations as JavaScript performs them | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 242 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 242 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 242 | ▶ | use Exporter qw( import ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 242 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 242 | our @EXPORT_OK = qw( js_lc js_trim js_ws_re js_blank ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # JavaScript's WhiteSpace and LineTerminator (what \s and String.prototype.trim take): unlike | ||||||||||||||||||||||||||||
| 14 | # Perl's \s, U+FEFF is one and U+0085 is none. | ||||||||||||||||||||||||||||
| 15 | 242 | my $WS = qr/[\t\n\x{0B}\f\r \x{A0}\x{1680}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}\x{FEFF}]/; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 103 | ▶ | sub js_ws_re { $WS } | ||||||||||||||||||||||||||
|
Subroutine
js_ws_re: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 12963 | ▶ | sub js_trim { | ||||||||||||||||||||||||||
|
Subroutine
js_trim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 12963 | my ( $s ) = @_; | |||||||||||||||||||||||||||
| 21 | 12963 | $s =~ s/\A$WS+//; | |||||||||||||||||||||||||||
| 22 | 12963 | $s =~ s/$WS+\z//; | |||||||||||||||||||||||||||
| 23 | 12963 | return $s; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 803 | ▶ | sub js_blank { | ||||||||||||||||||||||||||
|
Subroutine
js_blank: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 803 | my ( $s ) = @_; | |||||||||||||||||||||||||||
| 28 | 803 | ▶ | return js_trim($s) eq '' ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # String.prototype.toLowerCase: Perl's full lower-case mapping, plus the one context rule | ||||||||||||||||||||||||||||
| 32 | # JavaScript applies – a capital sigma ending a word is a final sigma. | ||||||||||||||||||||||||||||
| 33 | 12119 | ▶ | sub js_lc { | ||||||||||||||||||||||||||
|
Subroutine
js_lc: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 12119 | my ( $s ) = @_; | |||||||||||||||||||||||||||
| 35 | 12119 | ▶ | return lc $s unless $s =~ /\x{3A3}/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 1 | my @c = split //, $s; | |||||||||||||||||||||||||||
| 37 | 1 | my $out = ''; | |||||||||||||||||||||||||||
| 38 | 1 | for my $i ( 0 .. $#c ) { | |||||||||||||||||||||||||||
| 39 | 4 | ▶ | if ( $c[$i] eq "\x{3A3}" && _final_sigma( \@c, $i ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c[$i] eq "\x{3a3}" and _final_sigma(\@c, $i)
MC/DC50%1/2
$c[$i] eq "\x{3a3}" and _final_sigma(\@c, $i)
$c[$i] eq "\x{3a3}"
_final_sigma(\@c, $i)
Truth table66%2/3
A and B
A= $c[$i] eq "\x{3a3}"B= _final_sigma(\@c, $i)
| |||||||||||||||||||||||||||||
| 40 | 1 | $out .= "\x{3C2}"; | |||||||||||||||||||||||||||
| 41 | 1 | next; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 3 | $out .= lc $c[$i]; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 1 | return $out; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub _final_sigma { | ||||||||||||||||||||||||||
|
Subroutine
_final_sigma: called CC=8 SCAR=26.0
| |||||||||||||||||||||||||||||
| 49 | 1 | my ( $c, $i ) = @_; | |||||||||||||||||||||||||||
| 50 | 1 | my $j = $i - 1; | |||||||||||||||||||||||||||
| 51 | 1 | ▶ | $j-- while $j >= 0 && $c->[$j] =~ /\p{Case_Ignorable}/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$j >= 0 and $c->[$j] =~ /\p{Case_Ignorable}/
MC/DC0%0/2
$j >= 0 and $c->[$j] =~ /\p{Case_Ignorable}/
$j >= 0
$c->[$j] =~ /\p{Case_Ignorable}/
Truth table33%1/3
A and B
A= $j >= 0B= $c->[$j] =~ /\p{Case_Ignorable}/
| |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | return 0 unless $j >= 0 && $c->[$j] =~ /\p{Cased}/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$j >= 0 and $c->[$j] =~ /\p{Cased}/
MC/DC0%0/2
$j >= 0 and $c->[$j] =~ /\p{Cased}/
$j >= 0
$c->[$j] =~ /\p{Cased}/
Truth table33%1/3
A and B
A= $j >= 0B= $c->[$j] =~ /\p{Cased}/
| |||||||||||||||||||||||||||||
| 53 | 1 | my $k = $i + 1; | |||||||||||||||||||||||||||
| 54 | 1 | ▶ | $k++ while $k < @$c && $c->[$k] =~ /\p{Case_Ignorable}/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$k < @$c and $c->[$k] =~ /\p{Case_Ignorable}/
MC/DC0%0/2
$k < @$c and $c->[$k] =~ /\p{Case_Ignorable}/
$k < @$c
$c->[$k] =~ /\p{Case_Ignorable}/
Truth table33%1/3
A and B
A= $k < @$cB= $c->[$k] =~ /\p{Case_Ignorable}/
| |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | return !( $k < @$c && $c->[$k] =~ /\p{Cased}/ ); | ||||||||||||||||||||||||||
|
Condition33%1/3
$k < @$c && $c->[$k] =~ /\p{Cased}/
MC/DC0%0/2
$k < @$c && $c->[$k] =~ /\p{Cased}/
$k < @$c
$c->[$k] =~ /\p{Cased}/
Truth table33%1/3
A && B
A= $k < @$cB= $c->[$k] =~ /\p{Cased}/
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 242 | 1; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||||||||||