Change 15029 by jhi@alpha on 2002/03/05 01:39:29

        "The last pieces of Chinese puzzle" from Autrijus.

Affected files ...

.... //depot/perl/MANIFEST#756 edit
.... //depot/perl/ext/Encode/CN/CN.pm#4 edit
.... //depot/perl/ext/Encode/Encode.pm#64 edit
.... //depot/perl/ext/Encode/Encode/HZ.enc#2 delete
.... //depot/perl/ext/Encode/KR/KR.pm#3 edit
.... //depot/perl/ext/Encode/MANIFEST#5 edit
.... //depot/perl/ext/Encode/TW/TW.pm#4 edit
.... //depot/perl/ext/Encode/lib/Encode/CN/HZ.pm#1 add

Differences ...

==== //depot/perl/MANIFEST#756 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST.~1~   Mon Mar  4 18:45:05 2002
+++ perl/MANIFEST       Mon Mar  4 18:45:05 2002
@@ -296,7 +296,6 @@
 ext/Encode/Encode/gb1988.enc           Encode table
 ext/Encode/Encode/gb2312.enc           Encode table
 ext/Encode/Encode/gsm0338.enc          Encode table
-ext/Encode/Encode/HZ.enc               Encode table
 ext/Encode/Encode/ir-197.enc           Encode table
 ext/Encode/Encode/iso-ir-165.enc       Encode table
 ext/Encode/Encode/jis0201.enc          Encode table
@@ -338,6 +337,7 @@
 ext/Encode/JP/Makefile.PL      Encode extension
 ext/Encode/KR/KR.pm            Encode extension
 ext/Encode/KR/Makefile.PL              Encode extension
+ext/Encode/lib/Encode/CN/HZ.pm         Encode table
 ext/Encode/lib/Encode/Encoding.pm      Encode extension
 ext/Encode/lib/Encode/Internal.pm      Encode extension
 ext/Encode/lib/Encode/iso10646_1.pm    Encode extension
@@ -1145,8 +1145,8 @@
 lib/Math/BigInt/t/config.t     Test Math::BigInt->config()
 lib/Math/BigInt/t/constant.t   Test Math::BigInt/BigFloat under :constant
 lib/Math/BigInt/t/downgrade.t  Test if use Math::BigInt(); under downgrade works
+lib/Math/BigInt/t/inf_nan.t    Special tests for inf and NaN handling
 lib/Math/BigInt/t/isa.t                Test for Math::BigInt inheritance
-lib/Math/BigInt/t/inf_nan.t    Special tests for inf and NaN handling
 lib/Math/BigInt/t/mbimbf.inc   Actual BigInt/BigFloat accuracy, precicion and 
fallback, round_mode tests
 lib/Math/BigInt/t/mbimbf.t     BigInt/BigFloat accuracy, precicion and fallback, 
round_mode
 lib/Math/BigInt/t/require.t    Test if require Math::BigInt works

==== //depot/perl/ext/Encode/CN/CN.pm#4 (text) ====
Index: perl/ext/Encode/CN/CN.pm
--- perl/ext/Encode/CN/CN.pm.~1~        Mon Mar  4 18:45:05 2002
+++ perl/ext/Encode/CN/CN.pm    Mon Mar  4 18:45:05 2002
@@ -1,9 +1,14 @@
 package Encode::CN;
+our $VERSION = '0.02';
+
 use Encode;
-our $VERSION = '0.02';
+use Encode::CN::HZ;
 use XSLoader;
 XSLoader::load('Encode::CN',$VERSION);
 
+local $@;
+eval "use Encode::HanExtra"; # load extra encodings if they exist
+
 1;
 __END__
 =head1 NAME
@@ -25,7 +30,8 @@
   gb2312       The raw (low-bit) GB2312 character map
   gb12345      Traditional chinese counterpart to GB2312 (raw)
   iso-ir-165   GB2312 + GB6345 + GB8565 + additions
-  cp936        Code Page 936, also known as GBK (Extended GuoBiao)
+  cp936                Code Page 936, also known as GBK (Extended GuoBiao)
+  hz           7-bit escaped GB2312 encoding
 
 To find how to use this module in detail, see L<Encode>.
 
@@ -35,10 +41,11 @@
 separately on CPAN, under the name L<Encode::HanExtra>. That module
 also contains extra Taiwan-based encodings.
 
+This module will automatically load L<Encode::HanExtra> if you have it on
+your machine.
+
 =head1 BUGS
 
-The C<HZ> (Hanzi) escaped encoding is not supported.
-
 ASCII part (0x00-0x7f) is preserved for all encodings, even though it
 conflicts with mappings by the Unicode Consortium.  See
 

==== //depot/perl/ext/Encode/Encode.pm#64 (text) ====
Index: perl/ext/Encode/Encode.pm
--- perl/ext/Encode/Encode.pm.~1~       Mon Mar  4 18:45:05 2002
+++ perl/ext/Encode/Encode.pm   Mon Mar  4 18:45:05 2002
@@ -173,7 +173,6 @@
 # TODO: HP-UX '8' encodings arabic8 greek8 hebrew8 kana8 thai8 turkish8
 # TODO: HP-UX '15' encodings japanese15 korean15 roi15
 # TODO: Cyrillic encoding ISO-IR-111 (useful?)
-# TODO: Chinese encodings HZ
 # TODO: Armenian encoding ARMSCII-8
 # TODO: Hebrew encoding ISO-8859-8-1
 # TODO: Thai encoding TCVN

==== //depot/perl/ext/Encode/KR/KR.pm#3 (text) ====
Index: perl/ext/Encode/KR/KR.pm
--- perl/ext/Encode/KR/KR.pm.~1~        Mon Mar  4 18:45:05 2002
+++ perl/ext/Encode/KR/KR.pm    Mon Mar  4 18:45:05 2002
@@ -1,6 +1,7 @@
 package Encode::KR;
+our $VERSION = '0.02';
+
 use Encode;
-our $VERSION = '0.02';
 use XSLoader;
 XSLoader::load('Encode::KR',$VERSION);
 
@@ -23,7 +24,7 @@
 
   euc-kr       EUC (Extended Unix Character)
   ksc5601      Korean standard code set
-  cp949        Code Page 949 (EUC-KR + Unified Hangul Code)
+  cp949                Code Page 949 (EUC-KR + Unified Hangul Code)
   
 To find how to use this module in detail, see L<Encode>.
 

==== //depot/perl/ext/Encode/MANIFEST#5 (text) ====
Index: perl/ext/Encode/MANIFEST
--- perl/ext/Encode/MANIFEST.~1~        Mon Mar  4 18:45:05 2002
+++ perl/ext/Encode/MANIFEST    Mon Mar  4 18:45:05 2002
@@ -95,7 +95,6 @@
 Encode/gb1988.enc
 Encode/gb2312.enc
 Encode/gsm0338.enc
-Encode/HZ.enc
 Encode/iso-ir-165.enc
 Encode/ir-197.enc
 Encode/jis0201.enc
@@ -155,6 +154,7 @@
 lib/Encode/Unicode.pm
 lib/Encode/utf8.pm
 lib/Encode/XS.pm
+lib/Encode/CN/HZ.pm
 lib/Encode/Tcl/Escape.pm
 lib/Encode/Tcl/Extended.pm
 lib/Encode/Tcl/HanZi.pm

==== //depot/perl/ext/Encode/TW/TW.pm#4 (text) ====
Index: perl/ext/Encode/TW/TW.pm
--- perl/ext/Encode/TW/TW.pm.~1~        Mon Mar  4 18:45:05 2002
+++ perl/ext/Encode/TW/TW.pm    Mon Mar  4 18:45:05 2002
@@ -1,9 +1,13 @@
 package Encode::TW;
+our $VERSION = '0.02';
+
 use Encode;
-our $VERSION = '0.02';
 use XSLoader;
 XSLoader::load('Encode::TW',$VERSION);
 
+local $@;
+eval "use Encode::HanExtra"; # load extra encodings if they exist
+
 1;
 __END__
 =head1 NAME
@@ -23,7 +27,7 @@
 
   big5         The original Big5 encoding
   big5-hkscs   Big5 plus Cantonese characters in Hong Kong
-  cp950        Code Page 950 (Big5 + Microsoft vendor mappings)
+  cp950                Code Page 950 (Big5 + Microsoft vendor mappings)
   
 To find how to use this module in detail, see L<Encode>.
 
@@ -33,6 +37,9 @@
 (CMEX's Big5+) are distributed separately on CPAN, under the name
 L<Encode::HanExtra>. That module also contains extra China-based encodings.
 
+This module will automatically load L<Encode::HanExtra> if you have it on
+your machine.
+
 =head1 BUGS
 
 The C<CNS11643> encoding files are not complete (only the first two planes,

==== //depot/perl/ext/Encode/lib/Encode/CN/HZ.pm#1 (text) ====
Index: perl/ext/Encode/lib/Encode/CN/HZ.pm
--- perl/ext/Encode/lib/Encode/CN/HZ.pm.~1~     Mon Mar  4 18:45:05 2002
+++ perl/ext/Encode/lib/Encode/CN/HZ.pm Mon Mar  4 18:45:05 2002
@@ -0,0 +1,50 @@
+package Encode::CN::HZ;
+
+use Encode::CN;
+use Encode qw|encode decode|;
+use base 'Encode::Encoding';
+
+use strict;
+
+# HZ is but escaped GB, so we implement it with the
+# GB2312(raw) encoding here. Cf. RFC 1842 & 1843.
+
+my $canon = 'hz';
+my $obj = bless {name => $canon}, __PACKAGE__;
+$obj->Define($canon);
+
+sub decode
+{
+    my ($obj,$str,$chk) = @_;
+    my $gb = Encode::find_encoding('gb2312');
+
+    $str =~ s{~(?:(~)|\n|{([^~]*)~}|)}
+             {$1 ? '~' : defined $2 ? $gb->decode($2, $chk) : ''}eg;
+
+    return $str;
+}
+
+sub encode
+{
+    my ($obj,$str,$chk) = @_;
+    my $gb = Encode::find_encoding('gb2312');
+
+    $str =~ s/~/~~/g;
+    $str =~ s/((?:     
+       \p{InCJKCompatibility}|
+       \p{InCJKCompatibilityForms}|
+       \p{InCJKCompatibilityIdeographs}|
+       \p{InCJKCompatibilityIdeographsSupplement}|
+       \p{InCJKRadicalsSupplement}|
+       \p{InCJKSymbolsAndPunctuation}|
+       \p{InCJKUnifiedIdeographsExtensionA}|
+       \p{InCJKUnifiedIdeographs}|
+       \p{InCJKUnifiedIdeographsExtensionB}|
+       \p{InEnclosedCJKLettersAndMonths}
+    )+)/'~{'.$gb->encode($1, $chk).'~}'/egx;
+
+    return $str;
+}
+
+1;
+__END__
End of Patch.

Reply via email to