/[suikacvs]/perl/lib/Encode/HZ.pm
Suika

Diff of /perl/lib/Encode/HZ.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sun Sep 15 04:15:51 2002 UTC revision 1.4 by wakaba, Mon Oct 14 06:58:35 2002 UTC
# Line 3  use strict; Line 3  use strict;
3    
4  use vars qw($VERSION);  use vars qw($VERSION);
5  $VERSION = do {my @r =(q$Revision$ =~ /\d+/g);sprintf "%d."."%02d" x $#r, @r};  $VERSION = do {my @r =(q$Revision$ =~ /\d+/g);sprintf "%d."."%02d" x $#r, @r};
   
 use Encode ();  
 require Encode::CN;  
6  use base qw(Encode::Encoding);  use base qw(Encode::Encoding);
7  __PACKAGE__->Define(qw/hz hz-gb-2312/);  __PACKAGE__->Define(qw/hz chinese-hz hz-gb-2312 hz-gb2312 cp52936/);
8    
9  sub needs_lines  { 1 }  sub needs_lines  { 1 }
10    
# Line 18  sub perlio_ok { Line 15  sub perlio_ok {
15  sub decode  sub decode
16  {  {
17      my ($obj,$str,$chk) = @_;      my ($obj,$str,$chk) = @_;
18      my $gb = Encode::find_encoding('gb2312-raw');      my $gb = Encode::find_encoding($obj->__hz_encoding_name);
19    
20      $str =~ s{~                 # starting tilde      $str =~ s{~                 # starting tilde
21          (?:          (?:
# Line 42  sub decode Line 39  sub decode
39        if (defined $t) { # two tildes make one tilde        if (defined $t) { # two tildes make one tilde
40          '~';          '~';
41        } elsif (defined $c) {    # decode the characters        } elsif (defined $c) {    # decode the characters
42          $c =~ tr/\xA1-\xFE/\x21-\x7E/;          $c =~ tr/\x21-\x7E/\xA1-\xFE/;
43          $gb->decode($c, $chk);          $gb->decode($c, $chk);
44        } else {  # ~\n and invalid escape = ''        } else {  # ~\n and invalid escape = ''
45          '';          '';
# Line 55  sub decode Line 52  sub decode
52  sub encode ($$;$) {  sub encode ($$;$) {
53    my ($obj,$str,$chk) = @_;    my ($obj,$str,$chk) = @_;
54    $_[1] = '';    $_[1] = '';
55    my $gb = Encode::find_encoding('euc-cn');    my $gb = Encode::find_encoding($obj->__hz_encoding_name);
56        
57    $str =~ s/~/~~/g;    $str =~ s/~/~~/g;
58    $str = $gb->encode ($str, 1);    $str = $gb->encode ($str, 1);
# Line 68  sub encode ($$;$) { Line 65  sub encode ($$;$) {
65    $str;    $str;
66  }  }
67    
68  package Encode::HZ::HZ8;  sub __hz_encoding_name { 'euc-cn' }
69    
70    package Encode::HZ::HZ8;
71  use base qw(Encode::HZ);  use base qw(Encode::HZ);
72  __PACKAGE__->Define(qw/hz8 x-hz8/);  __PACKAGE__->Define(qw/hz8 x-hz8/);
73    
74  sub encode ($$;$) {  sub encode ($$;$) {
75    my ($obj,$str,$chk) = @_;    my ($obj,$str,$chk) = @_;
76    $_[1] = '';    $_[1] = '';
77    my $gb = Encode::find_encoding('euc-cn');    my $gb = Encode::find_encoding($obj->__hz_encoding_name);
78        
79    $str =~ s/~/~~/g;    $str =~ s/~/~~/g;
80    $str = $gb->encode ($str, 1);    $str = $gb->encode ($str, 1);
# Line 87  sub encode ($$;$) { Line 85  sub encode ($$;$) {
85    $str;    $str;
86  }  }
87    
88    package Encode::HZ::HZ165;
89    use base qw(Encode::HZ);
90    __PACKAGE__->Define(qw/hz-iso-ir-165 hz-isoir165 x-iso-ir-165-hz/);
91    
92    sub __hz_encoding_name { 'cn-gb-isoir165' }
93    
94  1;  1;
95  __END__  __END__
96    
   
97  =head1 NAME  =head1 NAME
98    
99  Encode::HZ --- Encode module for HZ (HZ-GB-2312), HZ8  Encode::HZ --- Encode module for HZ (HZ-GB-2312 and HZ for
100    ISO-IR 165) and HZ8
101    
102  =head1 DESCRIPTION  =head1 DESCRIPTION
103    
# Line 104  Note that Encode::CN::HZ, standard modul Line 108  Note that Encode::CN::HZ, standard modul
108  HZ (HZ-GB-2312 in IANA name), but other variants such as  HZ (HZ-GB-2312 in IANA name), but other variants such as
109  HZ8 can't be encoded/decode.  HZ8 can't be encoded/decode.
110    
111    =head1 ENCODINGS
112    
113    =over 4
114    
115    =item hz-gb-2312
116    
117    HZ 7-bit encoding for Chinese with GB 2312-80,
118    defined by RFC 1842 and RFC 1843.
119    (Alias: hz, chinese-hz (emacsen), CP52936 (M$),
120    hz-gb2312)
121    
122    Note that hz8 is also decodable with this encoding.
123    
124    =item hz8
125    
126    HZ 8-bit encoding for Chinese with GB 2312-80.
127    (Alias: x-hz8)
128    
129    Note that hz-gb-2312 is also decodable with this encoding.
130    
131    =item hz-iso-ir-165
132    
133    HZ 7-bit encoding for Chinese with ISO-IR 165
134    (syntax is same as hz-gb-2312, but coded character
135    set is differ) (Alias: hz-isoir165, x-iso-ir-165-hz)
136    
137    Note that you need load Encode module that support
138    'cn-gb-isoir165' encoding (defined by RFC 1922),
139    such as Encode::ISO2022::EightBit.
140    
141    Also note that since ISO-IR 165 is nealy superset of GB 2312-80,
142    hz-iso-ir-165 is also considerable as a superset of
143    hz-gb-2312.
144    
145    =back
146    
147  =head1 TODO  =head1 TODO
148    
149  Support of extended HZ such as EHZ.  Support of extended HZ such as EHZ.
# Line 120  This library is free software; you can r Line 160  This library is free software; you can r
160  and/or modify it under the same terms as Perl itself.  and/or modify it under the same terms as Perl itself.
161    
162  =cut  =cut
163    
164    # $Date$
165    ### HZ.pm ends here

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24