Utils/data/utils.pl

filter: Statementstmt 96.6% 86 / 89 Branchbran 77.7% 28 / 36 Conditioncond 80.9% 17 / 21 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 88.4% 146 / 165 CC 21 SCAR 24.5
CC
21
Cov
90%
build_map
17.1
add_map
4.0
esc
2.0
CRAP 11.6
« blib/lib/Unicode/Precis.pm ↑ Summary blib/lib/Unicode/Precis/Nickname.pm »
1  
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Encode qw(encode is_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Unicode::UCD qw(charinfo);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 my $init;
8 1 my $source_file = shift;
9 1 ▶if ($source_file and $source_file eq '--init') {
Branch: 1 branch
BranchTrueFalseTotal
if ($source_file and $source_file eq "--init") 0 1 1
Condition33%1/3
$source_file and $source_file eq "--init"
!ll&&!rl&&r
010
MC/DC0%0/2
$source_file and $source_file eq "--init"
$source_file $source_file eq "--init"
Truth table33%1/3
A and B
A= $source_fileB= $source_file eq "--init"
ABresult
0X0
100
111
10 0 $init = 1;
11 0 $source_file = shift;
12 }
13  
14 1 my $fh;
15 1 ▶open $fh, '<', $source_file or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $source_file or die $! 1 0 1
16 1 my $source = do { local $/; <$fh> };
17 1 close $fh;
18  
19 1 ▶if ($init) {
Branch: 1 branch
BranchTrueFalseTotal
if ($init) { } 0 1 1
20 0 $source =~
21 s{(/\* Begin auto-generated maps \*/).*(/\* End of auto-generated maps \*/)}
22 {$1\n\n$2}s
23 } else {
24 1 my $output = build_map();
25 1 ▶ $source =~
Branch: 1 branch
BranchTrueFalseTotal
$source =~ s[(/\* Begin auto-generated maps \*/).*(/\* End of auto-generated maps \*/)][$1\n\n$output$2]s or die 1 0 1
26 s{(/\* Begin auto-generated maps \*/).*(/\* End of auto-generated maps \*/)}
27 {$1\n\n$output$2}s
28 or die;
29 }
30  
31 1 unlink "$source_file.old";
32 1 ▶rename $source_file, "$source_file.old" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
rename $source_file, "$source_file.old" or die $! 1 0 1
33 1 ▶open $fh, '>', $source_file or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $source_file or die $! 1 0 1
34 1 print $fh $source;
35 1 close $fh;
36  
37 1 ▶sub build_map {
Subroutine build_map: called CC=17 SCAR=28.4
38 1 my $map = {};
39  
40 1 print STDERR "Loading property";
41 1 ▶ for (my $cp = 0x0; $cp <= 0x3FFFF; $cp++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cp <= 262143) 262144 1 262145
42 262144 ▶ print STDERR '.' unless $cp & 0xFFF;
Branch: 1 branch
BranchTrueFalseTotal
unless $cp & 4095 64 262080 262144
43 262144 my $charprop = charinfo($cp);
44 262144 ▶ next unless $charprop and %$charprop;
Branch: 1 branch
BranchTrueFalseTotal
unless $charprop and %$charprop 94167 167977 262144
Condition66%2/3
$charprop and %$charprop
!ll&&!rl&&r
941670167977
MC/DC50%1/2
$charprop and %$charprop
$charprop %$charprop
Truth table66%2/3
A and B
A= $charpropB= %$charprop
ABresult
0X0
100
111
45  
46 167977 my $category = $charprop->{category};
47 167977 ▶ if ($category and $category eq 'Zs' and $cp != 0x20) {
Branch: 1 branch
BranchTrueFalseTotal
if ($category and $category eq "Zs" and $cp != 32) 16 167961 167977
Condition83%5/6
$category and $category eq "Zs" and $cp != 32
!ll&&!rl&&r
167960116
$category and $category eq "Zs"
!ll&&!rl&&r
016796017
MC/DC66%2/3
$category and $category eq "Zs" and $cp != 32
$category $category eq "Zs" $cp != 32
Truth table75%3/4
A and B and C
A= $categoryB= $category eq "Zs"C= $cp != 32
ABCresult
0XX0
10X0
1100
1111
48 16 ▶ die sprintf 'Out of range: U+%02X', $cp
Branch: 1 branch
BranchTrueFalseTotal
if $cp < 128 0 16 16
49 if $cp < 0x80;
50  
51 16 add_map($map, 'space', $cp, "\x20");
52 }
53  
54 167977 my $decomposition = $charprop->{decomposition};
55 167977 ▶ if ($decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//) 226 167751 167977
Condition100%3/3
$decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//
!ll&&!rl&&r
15089116860226
MC/DC100%2/2
$decomposition and $decomposition =~ s/<(?:wide|narrow)>\s*//
$decomposition $decomposition =~ s/<(?:wide|narrow)>\s*//
Truth table100%3/3
A and B
A= $decompositionB= $decomposition =~ s/<(?:wide|narrow)>\s*//
ABresult
0X0
100
111
56 226 ▶ die sprintf 'Out of range: U+%02X', $cp
Branch: 1 branch
BranchTrueFalseTotal
if $cp < 128 0 226 226
57 if $cp < 0x80;
58  
59 add_map($map, 'widthdecomp', $cp,
60 226 pack('U*', map { hex "0x$_" } split(/\s+/, $decomposition)));
61 }
62 }
63 1 print STDERR "\n";
64  
65 1 my $output = '';
66 1 foreach my $mapname (reverse sort keys %$map) {
67 $output .= sprintf "static void *%s[%d] = {\n", $mapname,
68 17 scalar(@{$map->{$mapname}});
69  
70 17 my $len = 3;
71 17 $output .= ' ';
72 17 ▶ while (@{$map->{$mapname}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$map->{$mapname};}) 1088 17 1105
73 1088 my $c = shift @{$map->{$mapname}};
74 1088 ▶ $c ||= 'NULL';
Condition100%2/2
$c ||= "NULL"
l!l
257831
MC/DC100%1/1
$c ||= "NULL"
$c
Truth table100%2/2
A
A= $c
Aresult
11
00
75 1088 ▶ if (75 < $len + length(" $c,")) {
Branch: 1 branch
BranchTrueFalseTotal
if (75 < $len + length(" $c,")) 110 978 1088
76 110 $output .= "\n ";
77 110 $len = 3;
78 }
79 1088 $len += length(" $c,");
80 1088 $output .= " $c";
81 1088 ▶ $output .= ',' if @{$map->{$mapname}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$map->{$mapname};} 1071 17 1088
82 }
83  
84 17 $output .= "\n};\n\n";
85 }
86  
87 1 return $output;
88 }
89  
90 242 ▶sub add_map {
Subroutine add_map: called CC=4 SCAR=13.9
91 242 my $map = shift;
92 242 my $mapname = shift() . '_map';
93 242 my $cp = shift;
94 242 my $dest = shift;
95  
96 242 my $uc = pack 'U', $cp;
97 242 my $str = encode('UTF-8', $uc);
98 242 my @str = map { ord $_ } split //, $str;
99  
100 242 ▶ for (my $i = 0; $i < scalar(@str) - 1; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar(@str) - 1) 483 242 725
101 483 my $c = $str[$i];
102 483 my $newmapname = sprintf '%s_%02X', $mapname, $c;
103 483 ▶ $map->{$mapname} ||= [(undef) x 64];
Condition100%2/2
$map->{$mapname} ||= [(undef) x 64]
l!l
4767
MC/DC100%1/1
$map->{$mapname} ||= [(undef) x 64]
$map->{$mapname}
Truth table100%2/2
A
A= $map->{$mapname}
Aresult
11
00
104 483 $map->{$mapname}->[$c & 0x3F] = $newmapname;
105 483 $mapname = $newmapname;
106 }
107 242 ▶ $map->{$mapname} ||= [(undef) x 64];
Condition100%2/2
$map->{$mapname} ||= [(undef) x 64]
l!l
23210
MC/DC100%1/1
$map->{$mapname} ||= [(undef) x 64]
$map->{$mapname}
Truth table100%2/2
A
A= $map->{$mapname}
Aresult
11
00
108 242 $map->{$mapname}->[$str[-1] & 0x3F] = sprintf '"%s"', esc($dest);
109 }
110  
111 242 ▶sub esc {
Subroutine esc: called CC=2 SCAR=6.9
112 242 my $str = shift;
113 242 ▶ $str = encode('UTF-8', $str)
Branch: 1 branch
BranchTrueFalseTotal
if &is_utf8($str) 226 16 242
114 if is_utf8($str);
115  
116 242 $str =~ s{(.)}{sprintf '\\x%02X', ord $1}eg;
117 242 $str;
118 }
« blib/lib/Unicode/Precis.pm ↑ Summary blib/lib/Unicode/Precis/Nickname.pm »