| 1 | package Encode::KR::2022_KR; | ||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | our $VERSION = '2.05'; | |||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use Encode qw(:fallbacks); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 8 | ▶ | use parent qw(Encode::Encoding); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 8 | __PACKAGE__->Define('iso-2022-kr'); | |||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | sub needs_lines { 1 } | ||||||||
|
Subroutine
needs_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 12 | |||||||||||
| 13 | 0 | ▶ | sub perlio_ok { | ||||||||
|
Subroutine
perlio_ok: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 14 | 0 | return 0; # for the time being | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 5 | ▶ | sub decode { | ||||||||
|
Subroutine
decode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 18 | 5 | my ( $obj, $str, $chk ) = @_; | |||||||||
| 19 | 5 | ▶ | return undef unless defined $str; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 3 | my $res = $str; | |||||||||
| 21 | 3 | my $residue = iso_euc( \$res ); | |||||||||
| 22 | |||||||||||
| 23 | # This is for PerlIO | ||||||||||
| 24 | 3 | ▶ | $_[1] = $residue if $chk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 3 | return Encode::decode( 'euc-kr', $res, FB_PERLQQ ); | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 5 | ▶ | sub encode { | ||||||||
|
Subroutine
encode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 29 | 5 | my ( $obj, $utf8, $chk ) = @_; | |||||||||
| 30 | 5 | ▶ | return undef unless defined $utf8; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | # empty the input string in the stack so perlio is ok | ||||||||||
| 33 | 3 | ▶ | $_[1] = '' if $chk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 3 | my $octet = Encode::encode( 'euc-kr', $utf8, FB_PERLQQ ); | |||||||||
| 35 | 3 | euc_iso( \$octet ); | |||||||||
| 36 | 3 | return $octet; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 8 | ▶ | use Encode::CJKConstants qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | |||||||||||
| 41 | # ISO<->EUC | ||||||||||
| 42 | |||||||||||
| 43 | 3 | ▶ | sub iso_euc { | ||||||||
|
Subroutine
iso_euc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 44 | 3 | my $r_str = shift; | |||||||||
| 45 | 3 | $$r_str =~ s/$RE{'2022_KR'}//gox; # remove the designator | |||||||||
| 46 | 3 | $$r_str =~ s{ # replace characters in GL | |||||||||
| 47 | \x0e # between SO(\x0e) and SI(\x0f) | ||||||||||
| 48 | ([^\x0f]*) # with characters in GR | ||||||||||
| 49 | \x0f | ||||||||||
| 50 | } | ||||||||||
| 51 | { | ||||||||||
| 52 | 272 | my $out= $1; | |||||||||
| 53 | 272 | $out =~ tr/\x21-\x7e/\xa1-\xfe/; | |||||||||
| 54 | 272 | $out; | |||||||||
| 55 | }geox; | ||||||||||
| 56 | 3 | my ($residue) = ( $$r_str =~ s/(\e.*)$//so ); | |||||||||
| 57 | 3 | return $residue; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 3 | ▶ | sub euc_iso { | ||||||||
|
Subroutine
euc_iso: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 61 | 8 | ▶ | no warnings qw(uninitialized); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 3 | my $r_str = shift; | |||||||||
| 63 | substr( $$r_str, 0, 0 ) = | ||||||||||
| 64 | 3 | $ESC{'2022_KR'}; # put the designator at the beg. | |||||||||
| 65 | 3 | $$r_str =~ | |||||||||
| 66 | s{ # move KS X 1001 characters in GR to GL | ||||||||||
| 67 | ($RE{EUC_C}+) # and enclose them with SO and SI | ||||||||||
| 68 | }{ | ||||||||||
| 69 | 272 | my $str = $1; | |||||||||
| 70 | 272 | $str =~ tr/\xA1-\xFE/\x21-\x7E/; | |||||||||
| 71 | 272 | "\x0e" . $str . "\x0f"; | |||||||||
| 72 | }geox; | ||||||||||
| 73 | 3 | $$r_str; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 8 | 1; | |||||||||
| 77 | __END__ | ||||||||||