Upgrade to Encode 1.52, from Dan Kogai.
[p5sagit/p5-mst-13.2.git] / ext / Encode / lib / Encode / KR / 2022_KR.pm
CommitLineData
64ffdd5e 1package Encode::KR::2022_KR;
2use Encode::KR;
3use base 'Encode::Encoding';
4
5use strict;
6
6d1c0808 7our $VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
64ffdd5e 8
64ffdd5e 9
10my $canon = 'iso-2022-kr';
11my $obj = bless {name => $canon}, __PACKAGE__;
12$obj->Define($canon);
13
14sub name { return $_[0]->{name}; }
15
6d1c0808 16sub needs_lines { 1 }
17
64ffdd5e 18sub decode
19{
20 my ($obj,$str,$chk) = @_;
21 my $res = $str;
22 iso_euc(\$res);
23 return Encode::decode('euc-kr', $res, $chk);
24}
25
26sub encode
27{
28 my ($obj,$str,$chk) = @_;
29 my $res = Encode::encode('euc-kr', $str, $chk);
30 euc_iso(\$res);
31 return $res;
32}
33
34use Encode::CJKConstants qw(:all);
35
36# ISO<->EUC
37
67d7b5ef 38sub iso_euc{
64ffdd5e 39 my $r_str = shift;
6d1c0808 40 $$r_str =~ s/$RE{'2022_KR'}//gox; # remove the designator
67d7b5ef 41 $$r_str =~ s{ # replace chars. in GL
42 \x0e # between SO(\x0e) and SI(\x0f)
43 ([^\x0f]*) # with chars. in GR
44 \x0f
64ffdd5e 45 }
67d7b5ef 46 {
6d1c0808 47 my $out= $1;
67d7b5ef 48 $out =~ tr/\x21-\x7e/\xa1-\xfe/;
49 $out;
64ffdd5e 50 }geox;
51 $$r_str;
52}
53
54sub euc_iso{
55 my $r_str = shift;
6d1c0808 56 substr($$r_str,0,0)=$ESC{'2022_KR'}; # put the designator at the beg.
67d7b5ef 57 $$r_str =~ s{ # move KS X 1001 chars. in GR to GL
58 ($RE{EUC_C}+) # and enclose them with SO and SI
64ffdd5e 59 }{
60 my $str = $1;
64ffdd5e 61 $str =~ tr/\xA1-\xFE/\x21-\x7E/;
67d7b5ef 62 "\x0e" . $str . "\x0f";
64ffdd5e 63 }geox;
64ffdd5e 64 $$r_str;
65}
66
671;
68__END__
b2704119 69
70=head1 NAME
71
72Encode::KR::2022_KR -- internally used by Encode::KR
73
74=cut