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