Change 11998 by sky@sky-lab on 2001/09/11 07:52:06
Subject: [PATCH] Encode.pm add UCS-2 little endian support
From: Matt Sergeant <[EMAIL PROTECTED]>
Date: Tue, 11 Sep 2001 09:22:32 +0100
Message-ID: <315E8A8BF9D1D411AD3D00508BB1B0C004B9003C@UKS040>
Affected files ...
... //depot/perl/ext/Encode/Encode.pm#34 edit
Differences ...
==== //depot/perl/ext/Encode/Encode.pm#34 (text) ====
Index: perl/ext/Encode/Encode.pm
--- perl/ext/Encode/Encode.pm.~1~ Tue Sep 11 02:00:05 2001
+++ perl/ext/Encode/Encode.pm Tue Sep 11 02:00:05 2001
@@ -363,6 +363,44 @@
return $str;
}
+package Encode::ucs_2le;
+use base 'Encode::Encoding';
+
+__PACKAGE__->Define(qw(UCS-2le UCS-2LE ucs-2le));
+
+sub decode
+{
+ my ($obj,$str,$chk) = @_;
+ my $uni = '';
+ while (length($str))
+ {
+ my $code = unpack('v',substr($str,0,2,'')) & 0xffff;
+ $uni .= chr($code);
+ }
+ $_[1] = $str if $chk;
+ utf8::upgrade($uni);
+ return $uni;
+}
+
+sub encode
+{
+ my ($obj,$uni,$chk) = @_;
+ my $str = '';
+ while (length($uni))
+ {
+ my $ch = substr($uni,0,1,'');
+ my $x = ord($ch);
+ unless ($x < 32768)
+ {
+ last if ($chk);
+ $x = 0;
+ }
+ $str .= pack('v',$x);
+ }
+ $_[1] = $uni if $chk;
+ return $str;
+}
+
# switch back to Encode package in case we ever add AutoLoader
package Encode;
End of Patch.