blib/lib/HTML/HTML5/Parser/Charset/WebThai.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 69 CC 9 SCAR 23.0
CC
9
Cov
0%
encode
12.0
decode
12.0
encode
12.0
CRAP 10.0
1 #!/usr/bin/perl
2 package HTML::HTML5::Parser::Charset::WebThai;
3 ## skip Test::Tabs
4 use strict;
5 use warnings;
6 our $VERSION='0.992';
7  
8 ## NOTE: This module does not expect that its standalone uses.
9 ## See Message::Charset::Info for how it is used.
10  
11 require Encode::Encoding;
12 push our @ISA, 'Encode::Encoding';
13 __PACKAGE__->Define (qw/web-thai/);
14  
15 sub encode ($$;$) {
16 # $self, $str, $chk
17 if ($_[2]) {
18 if ($_[1] =~ s/^([\x00-\x7F\xA0\x{0E01}-\x{0E3A}\x{0E3F}-\x{0E5B}]+)//) {
19 return Encode::encode ('iso-8859-11', $1);
20 } else {
21 return '';
22 }
23 } else {
24 my $r = $_[1];
25 $r =~ s/[^\x00-\x7F\xA0\x{0E01}-\x{0E3A}\x{0E3F}-\x{0E5B}]/?/g;
26 return Encode::encode ('iso-8859-11', $r);
27 }
28 } # encode
29  
30 sub decode ($$;$) {
31 # $self, $s, $chk
32 if ($_[2]) {
33 my $r = '';
34 while (1) {
35 if ($_[1] =~ s/^([\x00-\x7F\xA0-\xDA\xDF-\xFB]+)//) {
36 $r .= Encode::decode ('iso-8859-11', $1);
37 } else {
38 return $r;
39 }
40 }
41 } else {
42 return Encode::decode ('windows-874', $_[1]);
43 }
44 } # decode
45  
46 package HTML::HTML5::Parser::Charset::WebThai::WebTIS620;
47 push our @ISA, 'Encode::Encoding';
48 __PACKAGE__->Define (qw/web-tis-620/);
49  
50 sub encode ($$;$) {
51 # $self, $str, $chk
52 if ($_[2]) {
53 if ($_[1] =~ s/^([\x00-\x7F\x{0E01}-\x{0E3A}\x{0E3F}-\x{0E5B}]+)//) {
54 return Encode::encode ('tis-620', $1);
55 } else {
56 return '';
57 }
58 } else {
59 my $r = $_[1];
60 $r =~ s/[^\x00-\x7F\x{0E01}-\x{0E3A}\x{0E3F}-\x{0E5B}]/?/g;
61 return Encode::encode ('tis-620', $r);
62 }
63 } # encode
64  
65 sub decode ($$;$) {
66 # $self, $s, $chk
67 if ($_[2]) {
68 my $r = '';
69 while (1) {
70 if ($_[1] =~ s/^([\x00-\x7F\xA1-\xDA\xDF-\xFB]+)//) {
71 $r .= Encode::decode ('tis-620', $1);
72 } else {
73 return $r;
74 }
75 }
76 } else {
77 return Encode::decode ('windows-874', $_[1]);
78 }
79 } # decode
80  
81 1;
82 ## $Date: 2008/09/10 10:27:09 $