line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Encode::IBM::939SOSI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
131
|
|
4
|
1
|
|
|
1
|
|
34
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
$VERSION = '1.01'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Encode (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use base qw(Encode::Encoding); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
461
|
|
10
|
|
|
|
|
|
|
__PACKAGE__->Define('ibm-939-sosi'); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $base37; |
13
|
|
|
|
|
|
|
my $base939; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub decode |
16
|
|
|
|
|
|
|
{ |
17
|
0
|
|
|
0
|
1
|
|
my ($obj,$str,$chk) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
0
|
|
|
|
$base37 ||= Encode::find_encoding('cp37'); |
20
|
0
|
|
0
|
|
|
|
$base939 ||= Encode::find_encoding('ibm-939'); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $out; |
23
|
0
|
|
|
|
|
|
foreach my $chunk (split(/\x0E([^\x0F]*\x0F)/, $str)) { |
24
|
0
|
0
|
|
|
|
|
if ($chunk =~ /\x0F\z/) { |
25
|
0
|
|
|
|
|
|
chop $chunk; |
26
|
0
|
|
|
|
|
|
$out .= $base939->decode($chunk); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
else { |
29
|
0
|
|
|
|
|
|
$out .= $base37->decode($chunk); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
0
|
|
|
|
|
|
return $out; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
1
|
|
my ($obj,$str,$chk) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
0
|
|
|
|
$base37 ||= Encode::find_encoding('cp37'); |
40
|
0
|
|
0
|
|
|
|
$base939 ||= Encode::find_encoding('ibm-939'); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if ($str =~ s/^([\x00-\xff]+)//) { |
|
|
0
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# english |
44
|
0
|
|
|
|
|
|
my $sub = $1; |
45
|
0
|
|
|
|
|
|
return $base37->encode($sub) . $obj->encode($str, $chk); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ($str =~ s/^([^\x00-\xff]+)//) { |
48
|
|
|
|
|
|
|
# chinese - shift in + shift out |
49
|
0
|
|
|
|
|
|
my $sub = $1; |
50
|
0
|
|
|
|
|
|
return "\x0E".$base939->encode($sub)."\x0F".$obj->encode($str, $chk); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
__END__ |