Integrate mainline (clean in Win32/MinGW but for end.t)
[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
7our $VERSION = do { my @r = (q$Revision: 0.99 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
8
9# Just for the time being, we implement jis-7bit
10# encoding via EUC
11
12my $canon = 'iso-2022-kr';
13my $obj = bless {name => $canon}, __PACKAGE__;
14$obj->Define($canon);
15
16sub name { return $_[0]->{name}; }
17
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
38sub iso_euc {
39 my $r_str = shift;
40 $$r_str =~ s(
41 ($RE{KSC_5601}|$RE{ISO_ASC})
42 ([^\e]*)
43 )
44 {
45 my ($esc, $str) = ($1, $2);
46 if ($esc !~ /$RE{ISO_ASC}/o) {
47 $str =~ tr/\x21-\x7e/\xa1-\xfe/;
48 }
49 $str;
50 }geox;
51 $$r_str;
52}
53
54sub euc_iso{
55 my $r_str = shift;
56 $$r_str =~ s{
57 ($RE{EUC_C}+)
58 }{
59 my $str = $1;
60 my $esc = $ESC{KSC_5601};
61 $str =~ tr/\xA1-\xFE/\x21-\x7E/;
62 $esc . $str . $ESC{ASC};
63 }geox;
64 $$r_str =~
65 s/\Q$ESC{ASC}\E(\Q$ESC{KSC_5601}\E)/$1/gox;
66 $$r_str;
67}
68
691;
70__END__