Re: ext/Encode/t/Tcl.t on VMS @15173
[p5sagit/p5-mst-13.2.git] / ext / Encode / lib / Encode / ucs2_le.pm
CommitLineData
df1df145 1package Encode::ucs_2le;
2use strict;
3our $VERSION = do {my @r=(q$Revision: 0.30 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r};
4use base 'Encode::Encoding';
5
6__PACKAGE__->Define(qw(UCS-2le UCS-2LE ucs-2le));
7
8sub decode
9{
10 my ($obj,$str,$chk) = @_;
11 my $uni = '';
12 while (length($str))
13 {
14 my $code = unpack('v',substr($str,0,2,'')) & 0xffff;
15 $uni .= chr($code);
16 }
17 $_[1] = $str if $chk;
18 utf8::upgrade($uni);
19 return $uni;
20}
21
22sub encode
23{
24 my ($obj,$uni,$chk) = @_;
25 my $str = '';
26 while (length($uni))
27 {
28 my $ch = substr($uni,0,1,'');
29 my $x = ord($ch);
30 unless ($x < 32768)
31 {
32 last if ($chk);
33 $x = 0;
34 }
35 $str .= pack('v',$x);
36 }
37 $_[1] = $uni if $chk;
38 return $str;
39}
401;
41__END__