summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl/lib/Encode/KR
diff options
context:
space:
mode:
authorReinhard Kotucha <reinhard.kotucha@web.de>2008-01-05 21:23:03 +0000
committerReinhard Kotucha <reinhard.kotucha@web.de>2008-01-05 21:23:03 +0000
commit61700e8be90ff6f495c0b1a9835fe07e9848de8d (patch)
treeba85dbc1413d5f834a501a8828e3b67678ba8524 /Master/tlpkg/tlperl/lib/Encode/KR
parent270728c6f3efcac6728d2c335c79824c356f428d (diff)
tlperl: Perl for scripts provided by TeX Live.
git-svn-id: svn://tug.org/texlive/trunk@6046 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Encode/KR')
-rw-r--r--Master/tlpkg/tlperl/lib/Encode/KR/2022_KR.pm79
1 files changed, 79 insertions, 0 deletions
diff --git a/Master/tlpkg/tlperl/lib/Encode/KR/2022_KR.pm b/Master/tlpkg/tlperl/lib/Encode/KR/2022_KR.pm
new file mode 100644
index 00000000000..8b4052be570
--- /dev/null
+++ b/Master/tlpkg/tlperl/lib/Encode/KR/2022_KR.pm
@@ -0,0 +1,79 @@
+package Encode::KR::2022_KR;
+use strict;
+
+our $VERSION = do { my @r = (q$Revision: 2.0 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+
+use Encode qw(:fallbacks);
+
+use base qw(Encode::Encoding);
+__PACKAGE__->Define('iso-2022-kr');
+
+sub needs_lines { 1 }
+
+sub perlio_ok {
+ return 0; # for the time being
+}
+
+sub decode
+{
+ my ($obj, $str, $chk) = @_;
+ my $res = $str;
+ 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, $utf8, $chk) = @_;
+ # empty the input string in the stack so perlio is ok
+ $_[1] = '' if $chk;
+ my $octet = Encode::encode('euc-kr', $utf8, FB_PERLQQ) ;
+ euc_iso(\$octet);
+ return $octet;
+}
+
+use Encode::CJKConstants qw(:all);
+
+# ISO<->EUC
+
+sub iso_euc{
+ my $r_str = shift;
+ $$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;
+ $out =~ tr/\x21-\x7e/\xa1-\xfe/;
+ $out;
+ }geox;
+ 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 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