File Coverage

blib/lib/Encode/IBM/835SOSI.pm
Criterion Covered Total %
statement 12 30 40.0
branch 0 6 0.0
condition 0 12 0.0
subroutine 4 6 66.6
pod 2 2 100.0
total 18 56 32.1


line stmt bran cond sub pod time code
1             package Encode::IBM::835SOSI;
2              
3 1     1   6 use strict;
  1         3  
  1         39  
4 1     1   5 use vars qw($VERSION);
  1         2  
  1         69  
5             $VERSION = '1.01';
6              
7 1     1   5 use Encode ();
  1         2  
  1         19  
8              
9 1     1   7 use base qw(Encode::Encoding);
  1         2  
  1         563  
10             __PACKAGE__->Define('ibm-835-sosi');
11              
12             my $base37;
13             my $base835;
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       $base835 ||= Encode::find_encoding('ibm-835');
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 .= $base835->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       $base835 ||= Encode::find_encoding('ibm-835');
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".$base835->encode($sub)."\x0F".$obj->encode($str, $chk);
51             }
52             }
53              
54             1;
55             __END__