Duh. If the input is a stream of UTF-8 bytes, all that's
[p5sagit/p5-mst-13.2.git] / ext / Encode / lib / Encode / 10646_1.pm
CommitLineData
64ffdd5e 1package Encode::10646_1;
df1df145 2use strict;
a999c27c 3our $VERSION = do { my @r = (q$Revision: 1.20 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
ee981de6 4
df1df145 5use base 'Encode::Encoding';
6# Encoding is 16-bit network order Unicode (no surogates)
7# Used for X font encodings
8
324bf92d 9__PACKAGE__->Define(qw(UCS-2));
df1df145 10
11sub decode
12{
13 my ($obj,$str,$chk) = @_;
14 my $uni = '';
15 while (length($str))
16 {
17 my $code = unpack('n',substr($str,0,2,'')) & 0xffff;
18 $uni .= chr($code);
19 }
20 $_[1] = $str if $chk;
324bf92d 21 utf8::upgrade($uni);
df1df145 22 return $uni;
23}
24
25sub encode
26{
27 my ($obj,$uni,$chk) = @_;
28 my $str = '';
29 while (length($uni))
30 {
31 my $ch = substr($uni,0,1,'');
32 my $x = ord($ch);
324bf92d 33 unless ($x < 32768)
df1df145 34 {
35 last if ($chk);
36 $x = 0;
37 }
38 $str .= pack('n',$x);
39 }
40 $_[1] = $uni if $chk;
41 return $str;
42}
431;
44__END__
67d7b5ef 45
46=head1 NAME
47
48Encode::10656_1 -- for internal use only
49
50=cut