blib/lib/HTML/HTML5/Parser/Charset/WebLatin1.pm

filter: Statementstmt 33.8% 21 / 62 Branchbran 12.5% 3 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 100% 2 / 2 totaltotal 30.2% 29 / 96 CC 13 SCAR 22.6
CC
13
Cov
28%
encode
12.0
decode
12.0
encode
12.0
CRAP 9.6
« blib/lib/HTML/HTML5/Parser/Charset/WebThai.pm ↑ Summary blib/lib/HTML/HTML5/Parser/Charset/UniversalCharDet.pm »
1 #!/usr/bin/perl
2 package HTML::HTML5::Parser::Charset::WebLatin1;
3 ## skip Test::Tabs
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $VERSION='0.991';
7  
8 ## NOTE: This module does not expect that its standalone uses.
9 ## See Message::Charset::Info for how it is used.
10  
11 1 require Encode::Encoding;
12 1 push our @ISA, 'Encode::Encoding';
13 1 __PACKAGE__->Define (qw/web-latin1/);
14  
15 sub encode ($$;$) {
16 # $self, $str, $chk
17 0 ▶ if ($_[2]) {
Subroutine encode: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 0 0 0
18 0 ▶ if ($_[1] =~ s/^([\x00-\x7F\xA0-\xFF]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ s/^([\x00-\x7F\xA0-\xFF]+)//) { } 0 0 0
19 0 return Encode::encode ('iso-8859-1', $1);
20 } else {
21 0 return '';
22 }
23 } else {
24 0 my $r = $_[1];
25 0 $r =~ s/[^\x00-\x7F\xA0-\xFF]/?/g;
26 0 return Encode::encode ('iso-8859-1', $r);
27 }
28 } # encode
29  
30 sub decode ($$;$) {
31 # $self, $s, $chk
32 0 ▶ if ($_[2]) {
Subroutine decode: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 0 0 0
33 0 my $r = '';
34 0 while (1) {
35 0 ▶ if ($_[1] =~ s/^([\x00-\x7F\xA0-\xFF]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ s/^([\x00-\x7F\xA0-\xFF]+)//) { } 0 0 0
36 0 $r .= $1;
37 #} elsif ($_[1] =~ s/^([\x80\x82-\x8C\x8E\x91-\x9C\x9E\x9F])//) {
38 # my $v = $1;
39 # $v =~ tr/\x80-\x9F/\x{20AC}\x{FFFD}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{FFFD}\x{017D}\x{FFFD}\x{FFFD}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{FFFD}\x{017E}\x{0178}/;
40 # $r .= $v;
41 } else {
42 0 return $r;
43 }
44 }
45 } else {
46 0 my $r = $_[1];
47 0 $r =~ tr/\x80-\x9F/\x{20AC}\x{FFFD}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{FFFD}\x{017D}\x{FFFD}\x{FFFD}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{FFFD}\x{017E}\x{0178}/;
48 0 return $r;
49 }
50 } # decode
51  
52 package HTML::HTML5::Parser::Charset::USASCII;
53 1 push our @ISA, 'Encode::Encoding';
54 1 __PACKAGE__->Define (qw/web-latin1-us-ascii/);
55  
56 sub encode ($$;$) {
57 # $self, $str, $chk
58 0 ▶ if ($_[2]) {
Subroutine encode: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 0 0 0
59 0 ▶ if ($_[1] =~ s/^([\x00-\x7F]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ s/^([\x00-\x7F]+)//) { } 0 0 0
60 0 return Encode::encode ('iso-8859-1', $1);
61 } else {
62 0 return '';
63 }
64 } else {
65 0 my $r = $_[1];
66 0 $r =~ s/[^\x00-\x7F]/?/g;
67 0 return Encode::encode ('iso-8859-1', $r);
68 }
69 } # encode
70  
71 sub decode ($$;$) {
72 # $self, $s, $chk
73 6 ▶ if ($_[2]) {
Subroutine decode: called CC=3 SCAR=11.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 6 0 6
74 6 my $r = '';
75 6 while (1) {
76 8 ▶ if ($_[1] =~ s/^([\x00-\x7F]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ s/^([\x00-\x7F]+)//) { } 2 6 8
77 2 $r .= $1;
78 #} elsif ($_[1] =~ s/^([\x80\x82-\x8C\x8E\x91-\x9C\x9E\x9F-\xFF])//) {
79 # my $v = $1;
80 # $v =~ tr/\x80-\xFF/\x{20AC}\x{FFFD}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{FFFD}\x{017D}\x{FFFD}\x{FFFD}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{FFFD}\x{017E}\x{0178}\xA0-\xFF/;
81 # $r .= $v;
82 } else {
83 6 return $r;
84 }
85 }
86 } else {
87 0 my $r = $_[1];
88 0 $r =~ tr/\x80-\xFF/\x{20AC}\x{FFFD}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{FFFD}\x{017D}\x{FFFD}\x{FFFD}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{FFFD}\x{017E}\x{0178}\xA0-\xFF/;
89 0 return $r;
90 }
91 } # decode
92  
93 package HTML::HTML5::Parser::Charset::WebLatin5;
94 1 push our @ISA, 'Encode::Encoding';
95 1 __PACKAGE__->Define (qw/web-latin5/);
96  
97 sub encode ($$;$) {
98 # $self, $str, $chk
99 0 ▶ if ($_[2]) {
Subroutine encode: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 0 0 0
100 0 ▶ if ($_[1] =~ s/^([\x00-\x7F]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ s/^([\x00-\x7F]+)//) { } 0 0 0
101 0 return Encode::encode ('iso-8859-9', $1);
102 } else {
103 0 return '';
104 }
105 } else {
106 0 my $r = $_[1];
107 0 $r =~ s/[^\x00-\x7F]/?/g;
108 0 return Encode::encode ('iso-8859-9', $r);
109 }
110 } # encode
111  
112 sub decode ($$;$) {
113 # $self, $s, $chk
114 0 ▶ if ($_[2]) {
Subroutine decode: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2]) { } 0 0 0
115 0 my $r = '';
116 0 while (1) {
117 0 ▶ if ($_[1] =~ s/^([\x00-\x7F\xA0-\xFF]+)//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ s/^([\x00-\x7F\xA0-\xFF]+)//) { } 0 0 0
118 0 $r .= Encode::decode ('windows-1254', $1);
119 #} elsif ($_[1] =~ s/^([\x80\x82-\x8C\x91-\x9C\x9F])//) {
120 # my $v = $1;
121 # $v =~ tr/\x80-\x9F/\x{20AC}\x{FFFD}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{FFFD}\x{FFFD}\x{FFFD}\x{FFFD}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{FFFD}\x{FFFD}\x{0178}/;
122 # $r .= $v;
123 } else {
124 0 return $r;
125 }
126 }
127 } else {
128 0 my $r = Encode::decode ('windows-1254', $_[1]);
129 0 return $r;
130 }
131 } # decode
132  
133 1 1;
134 ## $Date: 2008/09/10 10:27:09 $
« blib/lib/HTML/HTML5/Parser/Charset/WebThai.pm ↑ Summary blib/lib/HTML/HTML5/Parser/Charset/UniversalCharDet.pm »