| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # $Id: EUCJPMS.pm 7 2006-08-25 22:45:46Z naruse $ | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | package Encode::EUCJPMS; | ||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = "0.07"; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Encode qw(:fallbacks); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use XSLoader; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | XSLoader::load(__PACKAGE__,$VERSION); | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 1 | Encode::define_alias(qr/\beuc-?jp-?ms$/i => '"eucJP-ms"'); | |||||||||||||||||||||||||||||||
| 13 | 1 | Encode::define_alias(qr/\beuc-?jp-?win$/i => '"eucJP-ms"'); | |||||||||||||||||||||||||||||||
| 14 | 1 | Encode::define_alias(qr/\bglibc-EUC_JP_MS-2.3.3$/i => '"eucJP-ms"'); | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 1 | for my $name ('cp50220','cp50221'){ #, 'cp50222' | |||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my $h2z = ($name eq 'cp50220') ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 18 | 2 | my $jis0212 = 0; | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 2 | $Encode::Encoding{$name} = | |||||||||||||||||||||||||||||||
| 21 | bless { | ||||||||||||||||||||||||||||||||
| 22 | Name => $name, | ||||||||||||||||||||||||||||||||
| 23 | h2z => $h2z, | ||||||||||||||||||||||||||||||||
| 24 | jis0212 => $jis0212, | ||||||||||||||||||||||||||||||||
| 25 | } => __PACKAGE__; | ||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use base qw(Encode::Encoding); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | # we override this to 1 so PerlIO works | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub needs_lines { 1 } | ||||||||||||||||||||||||||||||
|
Subroutine
needs_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use Encode::CJKConstants qw(:all); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||
| 36 | # decode is identical for all 2022 variants | ||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | sub decode($$;$) | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
decode: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my ($obj, $str, $chk) = @_; | |||||||||||||||||||||||||||||||
| 42 | 0 | my $residue = ''; | |||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($chk){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | $str =~ s/([^\x00-\x7f].*)$//so and $residue = $1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||
| 46 | 0 | $residue .= jis_euc(\$str); | |||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $_[1] = $residue if $chk; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 48 | 0 | return Encode::decode('cp51932', $str, FB_PERLQQ); | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||
| 52 | # encode is different | ||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | sub encode($$;$) | ||||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 57 | 2 | require Encode::JP::H2Z; | |||||||||||||||||||||||||||||||
| 58 | 2 | my ($obj, $utf8, $chk) = @_; | |||||||||||||||||||||||||||||||
| 59 | # empty the input string in the stack so perlio is ok | ||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | $_[1] = '' if $chk; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 2 | my ($h2z, $jis0212) = @$obj{qw(h2z jis0212)}; | |||||||||||||||||||||||||||||||
| 62 | 2 | my $octet = Encode::encode('cp51932', $utf8, FB_PERLQQ) ; | |||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | $h2z and &Encode::JP::H2Z::h2z(\$octet); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | 2 | euc_jis(\$octet, $jis0212); | |||||||||||||||||||||||||||||||
| 65 | 2 | return $octet; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | # | ||||||||||||||||||||||||||||||||
| 69 | # cat_decode | ||||||||||||||||||||||||||||||||
| 70 | # | ||||||||||||||||||||||||||||||||
| 71 | 1 | my $re_scan_jis_g = qr{ | |||||||||||||||||||||||||||||||
| 72 | \G ( ($RE{JIS_0212}) | $RE{JIS_0208} | | ||||||||||||||||||||||||||||||||
| 73 | ($RE{ISO_ASC}) | ($RE{JIS_KANA}) | ) | ||||||||||||||||||||||||||||||||
| 74 | ([^\e]*) | ||||||||||||||||||||||||||||||||
| 75 | }x; | ||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub cat_decode { # ($obj, $dst, $src, $pos, $trm, $chk) | ||||||||||||||||||||||||||||||
|
Subroutine
cat_decode: not called CC=9 SCAR=43.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 77 | 0 | my ($obj, undef, undef, $pos, $trm) = @_; # currently ignores $chk | |||||||||||||||||||||||||||||||
| 78 | 0 | my ($rdst, $rsrc, $rpos) = \@_[1,2,3]; | |||||||||||||||||||||||||||||||
| 79 | 0 | local ${^ENCODING}; | |||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | use bytes; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 81 | 0 | my $opos = pos($$rsrc); | |||||||||||||||||||||||||||||||
| 82 | 0 | pos($$rsrc) = $pos; | |||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | while ($$rsrc =~ /$re_scan_jis_g/gc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 84 | 0 | my ($esc, $esc_0212, $esc_asc, $esc_kana, $chunk) = | |||||||||||||||||||||||||||||||
| 85 | ($1, $2, $3, $4, $5); | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | unless ($chunk) { $esc or last; next; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($esc && !$esc_asc) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$esc and not $esc_asc
MC/DC0%0/2
$esc and not $esc_asc
$esc
not $esc_asc
Truth table0%0/3
A and not(B)
A= $escB= not $esc_asc
| |||||||||||||||||||||||||||||||||
| 90 | 0 | $chunk =~ tr/\x21-\x7e/\xa1-\xfe/; | |||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($esc_kana) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 92 | 0 | $chunk =~ s/([\xa1-\xdf])/\x8e$1/og; | |||||||||||||||||||||||||||||||
| 93 | } elsif ($esc_0212) { | ||||||||||||||||||||||||||||||||
| 94 | 0 | $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | 0 | $chunk = Encode::decode('cp51932', $chunk, 0); | |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | elsif ((my $npos = index($chunk, $trm)) >= 0) { | ||||||||||||||||||||||||||||||||
| 99 | 0 | $$rdst .= substr($chunk, 0, $npos + length($trm)); | |||||||||||||||||||||||||||||||
| 100 | 0 | $$rpos += length($esc) + $npos + length($trm); | |||||||||||||||||||||||||||||||
| 101 | 0 | pos($$rsrc) = $opos; | |||||||||||||||||||||||||||||||
| 102 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | 0 | $$rdst .= $chunk; | |||||||||||||||||||||||||||||||
| 105 | 0 | $$rpos = pos($$rsrc); | |||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||
| 107 | 0 | $$rpos = pos($$rsrc); | |||||||||||||||||||||||||||||||
| 108 | 0 | pos($$rsrc) = $opos; | |||||||||||||||||||||||||||||||
| 109 | 0 | return ''; | |||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | # JIS<->EUC | ||||||||||||||||||||||||||||||||
| 113 | 1 | my $re_scan_jis = qr{ | |||||||||||||||||||||||||||||||
| 114 | (?:($RE{JIS_0212})|$RE{JIS_0208}|($RE{ISO_ASC})|($RE{JIS_KANA}))([^\e]*) | ||||||||||||||||||||||||||||||||
| 115 | }x; | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub jis_euc { | ||||||||||||||||||||||||||||||
|
Subroutine
jis_euc: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 118 | 0 | local ${^ENCODING}; | |||||||||||||||||||||||||||||||
| 119 | 0 | my $r_str = shift; | |||||||||||||||||||||||||||||||
| 120 | 0 | $$r_str =~ s($re_scan_jis) | |||||||||||||||||||||||||||||||
| 121 | { | ||||||||||||||||||||||||||||||||
| 122 | 0 | my ($esc_0212, $esc_asc, $esc_kana, $chunk) = | |||||||||||||||||||||||||||||||
| 123 | ($1, $2, $3, $4); | ||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (!$esc_asc) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | 0 | $chunk =~ tr/\x21-\x7e/\xa1-\xfe/; | |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if ($esc_kana) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 127 | 0 | $chunk =~ s/([\xa1-\xdf])/\x8e$1/og; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | elsif ($esc_0212) { | ||||||||||||||||||||||||||||||||
| 130 | 0 | $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og; | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | 0 | $chunk; | |||||||||||||||||||||||||||||||
| 134 | }geox; | ||||||||||||||||||||||||||||||||
| 135 | 0 | my ($residue) = ($$r_str =~ s/(\e.*)$//so); | |||||||||||||||||||||||||||||||
| 136 | 0 | return $residue; | |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | sub euc_jis{ | ||||||||||||||||||||||||||||||
|
Subroutine
euc_jis: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | no warnings qw(uninitialized); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 141 | 2 | my $r_str = shift; | |||||||||||||||||||||||||||||||
| 142 | 2 | my $jis0212 = shift; | |||||||||||||||||||||||||||||||
| 143 | 2 | $$r_str =~ s{ | |||||||||||||||||||||||||||||||
| 144 | ((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+) | ||||||||||||||||||||||||||||||||
| 145 | }{ | ||||||||||||||||||||||||||||||||
| 146 | 3 | my $chunk = $1; | |||||||||||||||||||||||||||||||
| 147 | my $esc = | ||||||||||||||||||||||||||||||||
| 148 | ( $chunk =~ tr/\x8E//d ) ? $ESC{KANA} : | ||||||||||||||||||||||||||||||||
| 149 | ( $chunk =~ tr/\x8F//d ) ? $ESC{JIS_0212} : | ||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | $ESC{JIS_0208}; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 151 | 3 | ▶ | if ($esc eq $ESC{JIS_0212} && !$jis0212){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$esc eq $Encode::EUCJPMS::ESC{"JIS_0212"} and not $jis0212
MC/DC0%0/2
$esc eq $Encode::EUCJPMS::ESC{"JIS_0212"} and not $jis0212
$esc eq $Encode::EUCJPMS::ESC{"JIS_0212"}
not $jis0212
Truth table33%1/3
A and not(B)
A= $esc eq $Encode::EUCJPMS::ESC{"JIS_0212"}B= not $jis0212
| |||||||||||||||||||||||||||||||||
| 152 | # fallback to '?' | ||||||||||||||||||||||||||||||||
| 153 | 0 | $chunk =~ tr/\xA1-\xFE/\x3F/; | |||||||||||||||||||||||||||||||
| 154 | }else{ | ||||||||||||||||||||||||||||||||
| 155 | 3 | $chunk =~ tr/\xA1-\xFE/\x21-\x7E/; | |||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||
| 157 | 3 | $esc . $chunk . $ESC{ASC}; | |||||||||||||||||||||||||||||||
| 158 | }geox; | ||||||||||||||||||||||||||||||||
| 159 | 2 | $$r_str =~ | |||||||||||||||||||||||||||||||
| 160 | s/\Q$ESC{ASC}\E | ||||||||||||||||||||||||||||||||
| 161 | (\Q$ESC{KANA}\E|\Q$ESC{JIS_0212}\E|\Q$ESC{JIS_0208}\E)/$1/gox; | ||||||||||||||||||||||||||||||||
| 162 | 2 | $$r_str; | |||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 1 | 1; | |||||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||||||