X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FEncode%2Flib%2FEncode%2FKR%2F2022_KR.pm;h=1bb584e3ca8d7a066c56e54dadca321cd0aa5d4d;hb=10c5ecbb45a6581439752935880506669f2d618c;hp=4a3b1d086a807b22c38f0cf974eebcc3c4751fa1;hpb=48e3bbddf569369fe6921f305df6ab7290c91152;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Encode/lib/Encode/KR/2022_KR.pm b/ext/Encode/lib/Encode/KR/2022_KR.pm index 4a3b1d0..1bb584e 100644 --- a/ext/Encode/lib/Encode/KR/2022_KR.pm +++ b/ext/Encode/lib/Encode/KR/2022_KR.pm @@ -1,32 +1,37 @@ package Encode::KR::2022_KR; -use Encode::KR; -use base 'Encode::Encoding'; - use strict; -our $VERSION = do { my @r = (q$Revision: 1.0 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +our $VERSION = do { my @r = (q$Revision: 1.5 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + +use Encode qw(:fallbacks); +use base qw(Encode::Encoding); +__PACKAGE__->Define('iso-2022-kr'); -my $canon = 'iso-2022-kr'; -my $obj = bless {name => $canon}, __PACKAGE__; -$obj->Define($canon); +sub needs_lines { 1 } -sub name { return $_[0]->{name}; } +sub perlio_ok { + return 0; # for the time being +} sub decode { - my ($obj,$str,$chk) = @_; + my ($obj, $str, $chk) = @_; my $res = $str; - iso_euc(\$res); - return Encode::decode('euc-kr', $res, $chk); + my $residue = iso_euc(\$res); + # This is for PerlIO + $_[1] = $residue if $chk; + return Encode::decode('euc-kr', $res, FB_PERLQQ); } sub encode { - my ($obj,$str,$chk) = @_; - my $res = Encode::encode('euc-kr', $str, $chk); - euc_iso(\$res); - return $res; + my ($obj, $utf8, $chk) = @_; + # empty the input string in the stack so perlio is ok + $_[1] = '' if $chk; + my $octet = Encode::encode('euc-jp', $utf8, FB_PERLQQ) ; + euc_iso(\$octet); + return $octet; } use Encode::CJKConstants qw(:all); @@ -35,32 +40,40 @@ use Encode::CJKConstants qw(:all); sub iso_euc{ my $r_str = shift; - $$r_str =~ s/$RE{'2022_KR'}//gox; # remove the designator - $$r_str =~ s{ # replace chars. in GL - \x0e # between SO(\x0e) and SI(\x0f) - ([^\x0f]*) # with chars. in GR + $$r_str =~ s/$RE{'2022_KR'}//gox; # remove the designator + $$r_str =~ s{ # replace characters in GL + \x0e # between SO(\x0e) and SI(\x0f) + ([^\x0f]*) # with characters in GR \x0f - } + } { - my $out= $1; + my $out= $1; $out =~ tr/\x21-\x7e/\xa1-\xfe/; $out; }geox; - $$r_str; + my ($residue) = ($$r_str =~ s/(\e.*)$//so); + return $residue; } sub euc_iso{ + no warnings qw(uninitialized); my $r_str = shift; - substr($$r_str,0,0)=$ESC{'2022_KR'}; # put the designator at the beg. - $$r_str =~ s{ # move KS X 1001 chars. in GR to GL - ($RE{EUC_C}+) # and enclose them with SO and SI - }{ - my $str = $1; - $str =~ tr/\xA1-\xFE/\x21-\x7E/; - "\x0e" . $str . "\x0f"; - }geox; + substr($$r_str,0,0)=$ESC{'2022_KR'}; # put the designator at the beg. + $$r_str =~ s{ # move KS X 1001 characters in GR to GL + ($RE{EUC_C}+) # and enclose them with SO and SI + }{ + my $str = $1; + $str =~ tr/\xA1-\xFE/\x21-\x7E/; + "\x0e" . $str . "\x0f"; + }geox; $$r_str; } 1; __END__ + +=head1 NAME + +Encode::KR::2022_KR -- internally used by Encode::KR + +=cut