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