Commit | Line | Data |
18586f54 |
1 | package Encode::iso10646_1; |
2 | use strict; |
3 | our $VERSION = do {my @r=(q$Revision: 0.30 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r}; |
4 | use base 'Encode::Encoding'; |
5 | # Encoding is 16-bit network order Unicode (no surogates) |
6 | # Used for X font encodings |
7 | |
8 | __PACKAGE__->Define(qw(UCS-2 iso-10646-1)); |
9 | |
10 | sub decode |
11 | { |
12 | my ($obj,$str,$chk) = @_; |
13 | my $uni = ''; |
14 | while (length($str)) |
15 | { |
16 | my $code = unpack('n',substr($str,0,2,'')) & 0xffff; |
17 | $uni .= chr($code); |
18 | } |
19 | $_[1] = $str if $chk; |
20 | utf8::upgrade($uni); |
21 | return $uni; |
22 | } |
23 | |
24 | sub encode |
25 | { |
26 | my ($obj,$uni,$chk) = @_; |
27 | my $str = ''; |
28 | while (length($uni)) |
29 | { |
30 | my $ch = substr($uni,0,1,''); |
31 | my $x = ord($ch); |
32 | unless ($x < 32768) |
33 | { |
34 | last if ($chk); |
35 | $x = 0; |
36 | } |
37 | $str .= pack('n',$x); |
38 | } |
39 | $_[1] = $uni if $chk; |
40 | return $str; |
41 | } |
42 | 1; |
43 | __END__ |