blib/lib/EBook/Ishmael/CharDet/EUCJP.pm

filter: Statementstmt 74.3% 58 / 78 Branchbran 68.7% 22 / 32 Conditioncond 40.0% 6 / 15 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 5 totaltotal 64.4% 96 / 149 CC 23 SCAR 33.2
CC
23
Cov
69%
take
40.1
confidence
3.8
bad
2.0
CRAP 27.8
« blib/lib/EBook/Ishmael/EBook/FictionBook2.pm ↑ Summary blib/lib/EBook/Ishmael/EBook/HTML.pm »
1 package EBook::Ishmael::CharDet::EUCJP;
2 18 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 our $VERSION = '2.03';
4 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶use EBook::Ishmael::CharDet::Constants qw(:CONSTANTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Generated from contrib/cjk2encodings.pl
10 18 my %EUCJP_FREQS = map { $_ => 1 } (
11 41428,41429,42190,42175,42148,42167,41378,42187,42186,42191,41379,42182,42184,
12 42155,42226,42150,42156,42219,42217,42183,42227,42210,42180,42179,42220,42159,
13 42163,42206,42176,42218,42146,42169,42157,42212,42165,42173,41430,41431,42216,
14 42223,42161,41404,42154,42177,42483,51424,42171,49101,42185,42209,42152,42425,
15 42207,42200,42221,45292,42168,42192,42194,42197,47275,48631,48592,51884,42189,
16 42203,48087,41382,45759,42441,42404,48118,42475,42224,42473,48362,48299,42440,
17 47296,42474,42463,45502,49895,46294,42170,48126,41397,47572,42162,42402,42208,
18 46575,50940,48869,50150,48082,50931,42195,48100,42164,45756,42431,42415,47779,
19 49076,42198,48340,51965,50126,45768,53460,53187,42438,49336,52444,49584,42435,
20 46500,42214,52905,42201,42158,42416,42453,42403,42424,51897,42406,42448,42181,
21 50942,52188,42178,42211,56806,42454,42160,42188,42436,42166,45744,49846,50123,
22 42477,42423,47333,42476,51882,47023,42462,50649,48573,42408,48360,48625,51119,
23 42204,48125,45269,47777,42215,50380,48814,42443,47591,51668,47357,49096,48048,
24 46262,52428,42467,52405,49587,50127,51700,42433,52416,52712,42427,48618,47565,
25 48876,46000,42174,48815,53725,52459,42411,49370,48848,50865,49893,42172,49384,
26 42410,49837,50624,49063,50602,48359,50149,52173,45755,48069,52387,42465,49316,
27 52149,49333,45809,49079,51186,50860,47815,49642,51926,52733,51896,46818,48096,
28 50361,45306,51671,48102,49065,47525,42412,50864,50875,56555,61690,41398,42439,
29 51948,51683,49070,52414,47358,42471,48880,48289,47083,47334,48051,42225,47810,
30 52452,51703,49340,45222,48355,52943,49876,48077,51669,50095,42413,48342,47614,
31 49094,46817,47351,52718,42419,50914,42455,50366,46313,52685,59105,47086,46837,
32 47326,49088,46511,52462,52442,52689,47586,49588,50678,49633,45258,50628,42432,
33 50134,50350,45996,51454,51105,47286,50424,52647,42193,45995,45793,49078,51916,
34 52693,42449,48581,48585,46770,42407,49863,46323,54748,42464,48322,47302,49896,
35 45776,42442,53154,46307,51151,46773,50893,50356,47854,48078,42421,50617,48095,
36 49325,42426,50347,49627,49339,50880,41432,47778,41433,42446,45283,50341,58051,
37 46558,45250,46828,51921,52412,47818,49125,48617,51390,61939,52212,42457,51413,
38 52695,48316,48072,49870,42484,52415,48373,53490,50889,51903,49854,50615,42469,
39 49084,56773,47080,52653,49830,48038,49855,52923,47340,47035,46045,45782,46536,
40 50122,48554,45810,51682,47783,49643,50663,50629,50682,46532,42414,45991,45764,
41 49145,53175,48314,48079,47833,52158,56539,42447,46546,45253,52404,47601,45763,
42 51679,45555,49087,47532,55464,51938,42461,51628,46296,48088,46787,50681,48370,
43 48081,45229,52420,47301,45811,45503,52964,51163,49648,50913,48545,52449,51414,
44 42417,54434,49390,46056,54761,46321,48835,51645,49360,49833,46509,42429,52154,
45 45815,57796,46762,45798,49326,51443,49872,52728,48872,53179,50401,45303,47352,
46 50102,42479,46832,49655,47285,46498,50639,51171,42460,50866,49573,46497,56014,
47 59834,49085,51444,52910,60925,48568,46030,49374,51922,48122,45774,50410,48338,
48 50427,49098,51650,46779,48298,46781,49366,42466,47041,51710,49140,46753,46042,
49 50157,49878,55544,48879,47090,50650,57514,45272,51964,46767,46792,49898,48068,
50 50147,51372,
51 );
52  
53 # https://www-archive.mozilla.org/projects/intl/universalcharsetdetection
54 18 my $DIST_RATIO = 0.93;
55  
56 sub new {
57  
58 67 ▶ my ($class) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
59  
60 67 my $self = {
61 Code => 0,
62 Left => 0,
63 Set => 0,
64 Freqs => 0,
65 MBs => 0,
66 Total => 0,
67 Bad => 0,
68 };
69  
70 67 return bless $self, $class;
71  
72 }
73  
74 sub take {
75  
76 5800 ▶ my ($self, $bytes) = @_;
Subroutine take: called CC=21 SCAR=36.9
Pod undocumented
77  
78 5800 ▶ return TAKE_BAD if $self->{Bad};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Bad"} 0 5800 5800
79  
80 5800 for my $i (0 .. length($bytes) - 1) {
81 92455 my $b = ord(substr $bytes, $i, 1) & 0xff;
82 92455 ▶ if ($self->{Set} == 3) {
Branch: 7 branches
BranchTrueFalseTotal
if ($self->{'Set'} == 3) { } 232 92223 92455
elsif ($self->{'Set'} == 2) { } 0 92223 92223
elsif ($self->{'Set'} == 1) { } 23013 69210 92223
elsif ($b == 143) { } 116 69094 69210
elsif ($b == 142) { } 0 69094 69094
elsif ($b >= 161 and $b <= 254) { } 23015 46079 69094
elsif ($b & 128) { } 24 46055 46079
83 232 ▶ if ($b < 0xa1 or $b > 0xfe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b < 161 or $b > 254) 0 232 232
Condition33%1/3
$b < 161 or $b > 254
l!l&&r!l&&!r
00232
MC/DC0%0/2
$b < 161 or $b > 254
$b < 161 $b > 254
Truth table33%1/3
A or B
A= $b < 161B= $b > 254
ABresult
1X1
011
000
84 0 $self->{Bad} = 1;
85 0 return TAKE_BAD;
86 }
87 232 $self->{Code} = ($self->{Code} << 8) | $b;
88 232 $self->{Left}--;
89 232 ▶ if ($self->{Left} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Left"} == 0) 116 116 232
90 116 ▶ if (exists $EUCJP_FREQS{ $self->{Code} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $EUCJP_FREQS{$self->{"Code"}}) 0 116 116
91 0 $self->{Freqs}++;
92 }
93 116 $self->{Total}++;
94 116 $self->{MBs}++;
95 116 $self->{Code} = 0;
96 116 $self->{Set} = 0;
97 }
98 } elsif ($self->{Set} == 2) {
99 0 ▶ if ($b < 0xa1 or $b > 0xdf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b < 161 or $b > 223) 0 0 0
Condition0%0/3
$b < 161 or $b > 223
l!l&&r!l&&!r
000
MC/DC0%0/2
$b < 161 or $b > 223
$b < 161 $b > 223
Truth table0%0/3
A or B
A= $b < 161B= $b > 223
ABresult
1X1
011
000
100 0 $self->{Bad} = 1;
101 0 return TAKE_BAD;
102 }
103 0 $self->{Code} = ($self->{Code} << 8) | $b;
104 0 $self->{Left}--;
105 0 ▶ if (exists $EUCJP_FREQS{ $self->{Code} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $EUCJP_FREQS{$self->{"Code"}}) 0 0 0
106 0 $self->{Freqs}++;
107 }
108 0 $self->{Total}++;
109 0 $self->{MBs}++;
110 0 $self->{Code} = 0;
111 0 $self->{Set} = 0;
112 } elsif ($self->{Set} == 1) {
113 # The range is supposed to be 0xa1-0xfe, but HP-16 allows for
114 # lower trailing bytes.
115 23013 ▶ if ($b < 0x21 or $b > 0xfe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b < 33 or $b > 254) 16 22997 23013
Condition66%2/3
$b < 33 or $b > 254
l!l&&r!l&&!r
16022997
MC/DC50%1/2
$b < 33 or $b > 254
$b < 33 $b > 254
Truth table66%2/3
A or B
A= $b < 33B= $b > 254
ABresult
1X1
011
000
116 16 $self->{Bad} = 1;
117 16 return TAKE_BAD;
118 }
119 22997 $self->{Code} = ($self->{Code} << 8) | $b;
120 22997 ▶ if (exists $EUCJP_FREQS{ $self->{Code} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $EUCJP_FREQS{$self->{"Code"}}) 6427 16570 22997
121 6427 $self->{Freqs}++;
122 }
123 22997 $self->{Left}--;
124 22997 $self->{MBs}++;
125 22997 $self->{Total}++;
126 22997 $self->{Code} = 0;
127 22997 $self->{Set} = 0;
128 } elsif ($b == 0x8f) {
129 116 $self->{Set} = 3;
130 116 $self->{Left} = 2;
131 116 $self->{Code} = $b;
132 } elsif ($b == 0x8e) {
133 0 $self->{Set} = 2;
134 0 $self->{Left} = 1;
135 0 $self->{Code} = $b;
136 ▶ } elsif ($b >= 0xa1 && $b <= 0xfe) {
Condition66%2/3
$b >= 161 and $b <= 254
!ll&&!rl&&r
46079023015
MC/DC50%1/2
$b >= 161 and $b <= 254
$b >= 161 $b <= 254
Truth table66%2/3
A and B
A= $b >= 161B= $b <= 254
ABresult
0X0
100
111
137 23015 $self->{Set} = 1;
138 23015 $self->{Left} = 1;
139 23015 $self->{Code} = $b;
140 } elsif ($b & 0x80) {
141 24 $self->{Bad} = 1;
142 24 return TAKE_BAD;
143 } else {
144 46055 $self->{Total}++;
145 }
146 }
147  
148 5760 return TAKE_OK;
149  
150 }
151  
152 sub confidence {
153  
154 7 ▶ my ($self) = @_;
Subroutine confidence: called CC=3 SCAR=13.3
Pod undocumented
155  
156 7 ▶ if ($self->{Bad} or $self->{MBs} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Bad"} or $self->{"MBs"} == 0) 0 7 7
Condition33%1/3
$self->{"Bad"} or $self->{"MBs"} == 0
l!l&&r!l&&!r
007
MC/DC0%0/2
$self->{"Bad"} or $self->{"MBs"} == 0
$self->{"Bad"} $self->{"MBs"} == 0
Truth table33%1/3
A or B
A= $self->{"Bad"}B= $self->{"MBs"} == 0
ABresult
1X1
011
000
157 0 return 0;
158 }
159  
160 7 return $self->{Freqs} / $self->{MBs};
161  
162 }
163  
164 sub bad {
165  
166 0 ▶ my ($self) = @_;
Subroutine bad: not called CC=1 SCAR=6.9
Pod undocumented
167  
168 0 return $self->{Bad};
169  
170 }
171  
172 7 ▶sub encoding { 'EUC-JP' }
Subroutine encoding: called CC=1 SCAR=0.0
Pod undocumented
173  
174 18 1;
175  
« blib/lib/EBook/Ishmael/EBook/FictionBook2.pm ↑ Summary blib/lib/EBook/Ishmael/EBook/HTML.pm »