Commit | Line | Data |
64ffdd5e |
1 | package Encode::KR::2022_KR; |
2 | use Encode::KR; |
3 | use base 'Encode::Encoding'; |
4 | |
5 | use strict; |
6 | |
7 | our $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 | |
12 | my $canon = 'iso-2022-kr'; |
13 | my $obj = bless {name => $canon}, __PACKAGE__; |
14 | $obj->Define($canon); |
15 | |
16 | sub name { return $_[0]->{name}; } |
17 | |
18 | sub 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 | |
26 | sub 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 | |
34 | use Encode::CJKConstants qw(:all); |
35 | |
36 | # ISO<->EUC |
37 | |
38 | sub 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 | |
54 | sub 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 | |
69 | 1; |
70 | __END__ |