1N/Apackage Encode::KR::2022_KR;
1N/Ause strict;
1N/A
1N/Aour $VERSION = do { my @r = (q$Revision: 1.6 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
1N/A
1N/Ause Encode qw(:fallbacks);
1N/A
1N/Ause base qw(Encode::Encoding);
1N/A__PACKAGE__->Define('iso-2022-kr');
1N/A
1N/Asub needs_lines { 1 }
1N/A
1N/Asub perlio_ok {
1N/A return 0; # for the time being
1N/A}
1N/A
1N/Asub decode
1N/A{
1N/A my ($obj, $str, $chk) = @_;
1N/A my $res = $str;
1N/A my $residue = iso_euc(\$res);
1N/A # This is for PerlIO
1N/A $_[1] = $residue if $chk;
1N/A return Encode::decode('euc-kr', $res, FB_PERLQQ);
1N/A}
1N/A
1N/Asub encode
1N/A{
1N/A my ($obj, $utf8, $chk) = @_;
1N/A # empty the input string in the stack so perlio is ok
1N/A $_[1] = '' if $chk;
1N/A my $octet = Encode::encode('euc-kr', $utf8, FB_PERLQQ) ;
1N/A euc_iso(\$octet);
1N/A return $octet;
1N/A}
1N/A
1N/Ause Encode::CJKConstants qw(:all);
1N/A
1N/A# ISO<->EUC
1N/A
1N/Asub iso_euc{
1N/A my $r_str = shift;
1N/A $$r_str =~ s/$RE{'2022_KR'}//gox; # remove the designator
1N/A $$r_str =~ s{ # replace characters in GL
1N/A \x0e # between SO(\x0e) and SI(\x0f)
1N/A ([^\x0f]*) # with characters in GR
1N/A \x0f
1N/A }
1N/A {
1N/A my $out= $1;
1N/A $out =~ tr/\x21-\x7e/\xa1-\xfe/;
1N/A $out;
1N/A }geox;
1N/A my ($residue) = ($$r_str =~ s/(\e.*)$//so);
1N/A return $residue;
1N/A}
1N/A
1N/Asub euc_iso{
1N/A no warnings qw(uninitialized);
1N/A my $r_str = shift;
1N/A substr($$r_str,0,0)=$ESC{'2022_KR'}; # put the designator at the beg.
1N/A $$r_str =~ s{ # move KS X 1001 characters in GR to GL
1N/A ($RE{EUC_C}+) # and enclose them with SO and SI
1N/A }{
1N/A my $str = $1;
1N/A $str =~ tr/\xA1-\xFE/\x21-\x7E/;
1N/A "\x0e" . $str . "\x0f";
1N/A }geox;
1N/A $$r_str;
1N/A}
1N/A
1N/A1;
1N/A__END__
1N/A
1N/A=head1 NAME
1N/A
1N/AEncode::KR::2022_KR -- internally used by Encode::KR
1N/A
1N/A=cut