| 1 | package Encode::JIS2K::2022JP3; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = do { my @r = (q$Revision: 0.03 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Encode qw(:fallbacks); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base qw(Encode::Encoding); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | my $Canon = 'iso-2022-jp-3'; | |||||||||||||||||||||||||||
| 11 | 1 | $Encode::Encoding{$Canon} = | |||||||||||||||||||||||||||
| 12 | bless { | ||||||||||||||||||||||||||||
| 13 | Name => $Canon, | ||||||||||||||||||||||||||||
| 14 | h2z => 1, | ||||||||||||||||||||||||||||
| 15 | jis0212 => 1, | ||||||||||||||||||||||||||||
| 16 | } => __PACKAGE__; | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # we override this to 1 so PerlIO works | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub needs_lines { 1 } | ||||||||||||||||||||||||||
|
Subroutine
needs_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Encode::CJKConstants qw(:all); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | our $DEBUG = 0; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | # decode is identical for all 2022 variants | ||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub decode($$;$) | ||||||||||||||||||||||||||||
| 30 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=4 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 2 | my ($obj, $str, $chk) = @_; | |||||||||||||||||||||||||||
| 32 | 2 | my $residue = ''; | |||||||||||||||||||||||||||
| 33 | 2 | ▶ | if ($chk){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | $str =~ s/([^\x00-\x7f].*)$//so; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | $1 and $residue = $1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | 2 | $residue .= jis_euc(\$str); | |||||||||||||||||||||||||||
| 38 | 2 | ▶ | $_[1] = $residue if $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 2 | return Encode::decode('euc-jisx0213', $str, FB_PERLQQ); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||
| 43 | # encode is different | ||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub encode($$;$) | ||||||||||||||||||||||||||||
| 47 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 2 | require Encode::JP::H2Z; | |||||||||||||||||||||||||||
| 49 | 2 | my ($obj, $utf8, $chk) = @_; | |||||||||||||||||||||||||||
| 50 | # empty the input string in the stack so perlio is ok | ||||||||||||||||||||||||||||
| 51 | 2 | ▶ | $_[1] = '' if $chk; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 2 | my ($h2z, $jis0212) = @$obj{qw(h2z jis0212)}; | |||||||||||||||||||||||||||
| 53 | 2 | my $octet = Encode::encode('euc-jisx0213', $utf8, FB_PERLQQ) ; | |||||||||||||||||||||||||||
| 54 | 2 | ▶ | $h2z and &Encode::JP::H2Z::h2z(\$octet); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 2 | euc_jis(\$octet, $jis0212); | |||||||||||||||||||||||||||
| 56 | 2 | return $octet; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | our $ESC_JISX0213_1 = "\e\$(O"; | |||||||||||||||||||||||||||
| 62 | 1 | our $ESC_JISX0213_2 = "\e\$(P"; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # JIS<->EUC | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub jis_euc { | ||||||||||||||||||||||||||
|
Subroutine
jis_euc: called CC=4 SCAR=24.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 2 | my $r_str = shift; | |||||||||||||||||||||||||||
| 68 | 2 | $$r_str =~ s( | |||||||||||||||||||||||||||
| 69 | ($RE{JIS_0212}|$RE{JIS_0208}|$RE{ISO_ASC}|$RE{JIS_KANA}) | ||||||||||||||||||||||||||||
| 70 | ([^\e]*) | ||||||||||||||||||||||||||||
| 71 | ) | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | my ($esc, $chunk) = ($1, $2); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($esc !~ /$RE{ISO_ASC}/o) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $chunk =~ tr/\x21-\x7e/\xa1-\xfe/; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($esc =~ /$RE{JIS_KANA}/o) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | 0 | $chunk =~ s/([\xa1-\xdf])/\x8e$1/og; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | elsif ($esc =~ /$RE{JIS_0212}/o) { | ||||||||||||||||||||||||||||
| 80 | 0 | $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 0 | $chunk; | |||||||||||||||||||||||||||
| 84 | }geox; | ||||||||||||||||||||||||||||
| 85 | 2 | my ($residue) = ($$r_str =~ s/(\e.*)$//so); | |||||||||||||||||||||||||||
| 86 | 2 | return $residue; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | sub euc_jis{ | ||||||||||||||||||||||||||
|
Subroutine
euc_jis: called CC=5 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 1 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | 2 | my $r_str = shift; | |||||||||||||||||||||||||||
| 92 | 2 | my $jis0212 = shift; | |||||||||||||||||||||||||||
| 93 | 2 | $$r_str =~ s{ | |||||||||||||||||||||||||||
| 94 | ((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+) | ||||||||||||||||||||||||||||
| 95 | }{ | ||||||||||||||||||||||||||||
| 96 | 0 | my $chunk = $1; | |||||||||||||||||||||||||||
| 97 | my $esc = | ||||||||||||||||||||||||||||
| 98 | ( $chunk =~ tr/\x8E//d ) ? $ESC{KANA} : | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | ( $chunk =~ tr/\x8F//d ) ? $ESC_JISX0213_2 : | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 100 | $ESC_JISX0213_1; | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($esc eq $ESC_JISX0213_2 && !$jis0212){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$esc eq $Encode::JIS2K::2022JP3::ESC_JISX0213_2 and not $jis0212
MC/DC0%0/2
$esc eq $Encode::JIS2K::2022JP3::ESC_JISX0213_2 and not $jis0212
$esc eq $Encode::JIS2K::2022JP3::ESC_JISX0213_2
not $jis0212
Truth table0%0/3
A and not(B)
A= $esc eq $Encode::JIS2K::2022JP3::ESC_JISX0213_2B= not $jis0212
| |||||||||||||||||||||||||||||
| 102 | # fallback to '?' | ||||||||||||||||||||||||||||
| 103 | 0 | $chunk =~ tr/\xA1-\xFE/\x3F/; | |||||||||||||||||||||||||||
| 104 | }else{ | ||||||||||||||||||||||||||||
| 105 | 0 | $chunk =~ tr/\xA1-\xFE/\x21-\x7E/; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | $esc . $chunk . $ESC{ASC}; | |||||||||||||||||||||||||||
| 108 | }geox; | ||||||||||||||||||||||||||||
| 109 | 2 | $$r_str =~ | |||||||||||||||||||||||||||
| 110 | s/\Q$ESC{ASC}\E | ||||||||||||||||||||||||||||
| 111 | (\Q$ESC{KANA}\E|\Q$ESC_JISX0213_1\E|\Q$ESC_JISX0213_2\E)/$1/gox; | ||||||||||||||||||||||||||||
| 112 | 2 | $$r_str; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 1 | 1; | |||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||