blib/lib/Encode/EUCJPASCII.pm

filter: Statementstmt 63.0% 58 / 92 Branchbran 17.8% 5 / 28 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 83.3% 10 / 12 Podpod 100% 4 / 4 totaltotal 49.0% 78 / 159 CC 20 SCAR 44.4
CC
20
Cov
47%
cat_decode
184.1
decode
6.4
encode
2.0
CRAP 84.8
↑ Summary EUCJPASCII.c »
1 package Encode::EUCJPASCII;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 our $VERSION = "0.03";
5
6 1 ▶use Encode qw(:fallbacks);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 XSLoader::load(__PACKAGE__,$VERSION);
9  
10 1 Encode::define_alias(qr/\beuc-?jp(-?open)?(-?19970715)?-?ascii$/i
11 => '"eucJP-ascii"');
12 1 Encode::define_alias(qr/\b(x-)?iso-?2022-?jp-?ascii$/i
13 => '"x-iso2022jp-ascii"');
14  
15 1 my $name = 'x-iso2022jp-ascii';
16 1 $Encode::Encoding{$name} = bless { Name => $name } => __PACKAGE__;
17  
18 1 ▶use base qw(Encode::Encoding);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # we override this to 1 so PerlIO works
21 0 ▶sub needs_lines { 1 }
Subroutine needs_lines: not called CC=1 SCAR=6.9
Pod documented
22  
23 1 ▶use Encode::CJKConstants qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Encode::JP::JIS7;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # 26 row-cell pairs swapped between JIS C 6226-1978 and JIS X 0208-1983.
27 # cf. JIS X 0208:1997 Annex 2 Table 1.
28 1 my @swap1978 = ("\x30\x33" => "\x72\x4D", "\x32\x29" => "\x72\x74",
29 "\x33\x42" => "\x69\x5a", "\x33\x49" => "\x59\x78",
30 "\x33\x76" => "\x63\x5e", "\x34\x43" => "\x5e\x75",
31 "\x34\x52" => "\x6b\x5d", "\x37\x5b" => "\x70\x74",
32 "\x39\x5c" => "\x62\x68", "\x3c\x49" => "\x69\x22",
33 "\x3F\x59" => "\x70\x57", "\x41\x28" => "\x6c\x4d",
34 "\x44\x5B" => "\x54\x64", "\x45\x57" => "\x62\x6a",
35 "\x45\x6e" => "\x5b\x6d", "\x45\x73" => "\x5e\x39",
36 "\x46\x76" => "\x6d\x6e", "\x47\x68" => "\x6a\x24",
37 "\x49\x30" => "\x5B\x58", "\x4b\x79" => "\x50\x56",
38 "\x4c\x79" => "\x69\x2e", "\x4F\x36" => "\x64\x46",
39 "\x36\x46" => "\x74\x21", "\x4B\x6A" => "\x74\x22",
40 "\x4D\x5A" => "\x74\x23", "\x60\x76" => "\x74\x24",
41 );
42 1 my %swap1978 = (@swap1978, reverse @swap1978);
43  
44 8 ▶sub decode($$;$) {
Subroutine decode: called CC=6 SCAR=18.6
Pod documented
45 8 my ( $obj, $str, $chk ) = @_;
46 8 my $residue = '';
47 8 ▶ if ($chk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chk) 0 8 8
48 0 ▶ $str =~ s/([^\x00-\x7f].*)$//so and $residue = $1;
Branch: 1 branch
BranchTrueFalseTotal
$str =~ s/([^\x00-\x7f].*)$//os and $residue = $1 0 0 0
49 }
50 # Handle JIS X 0201 sequences.
51 8 $str =~ s{\e\(J ([^\e]*) (?:\e\(B)?}{
52 3 my $s = $1;
53 3 $s =~ s{([\x5C\x7E]+)}{
54 3 my $c = $1;
55 3 $c =~ s/\x5C/\x21\x6F/g;
56 3 $c =~ s/\x7E/\x21\x31/g;
57 3 "\e\$B".$c."\e(B";
58 }eg;
59 3 ▶ ($s =~ /^\e/? "\e(B": '').$s;
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /^\e/ ? : 1 2 3
60 }egsx;
61 # Handle JIS C 6226-1978 sequences.
62 8 $str =~ s{\e\$\@ ([^\e]*) (?:\e\$B)?}{
63 1 my $s = $1;
64 1 ▶ $s =~ s{([\x21-\x7E]{2})}{$swap1978{$1} || $1}eg;
Condition33%1/3
$swap1978{$1} || $1
l!l&&r!l&&!r
5200
MC/DC0%0/2
$swap1978{$1} || $1
$swap1978{$1} $1
Truth table33%1/3
A || B
A= $swap1978{$1}B= $1
ABresult
1X1
011
000
65 1 "\e\$B".$s;
66 }egsx;
67 8 $residue .= Encode::JP::JIS7::jis_euc( \$str );
68 8 ▶ $_[1] = $residue if $chk;
Branch: 1 branch
BranchTrueFalseTotal
if $chk 0 8 8
69 8 return Encode::decode( 'eucJP-ascii', $str, $chk );
70 }
71  
72 8 ▶sub encode($$;$) {
Subroutine encode: called CC=2 SCAR=7.0
Pod documented
73 8 my ( $obj, $utf8, $chk ) = @_;
74  
75 # empty the input string in the stack so perlio is ok
76 8 ▶ $_[1] = '' if $chk;
Branch: 1 branch
BranchTrueFalseTotal
if $chk 0 8 8
77 8 my $octet = Encode::encode( 'eucJP-ascii', $utf8, $chk );
78 8 Encode::JP::JIS7::euc_jis( \$octet, 1 );
79 8 return $octet;
80 }
81  
82 #
83 # cat_decode
84 #
85 1 my $re_scan_jis_g = qr{
86 \G ( ($RE{JIS_0212}) | (\e\$\@) | $RE{JIS_0208} |
87 (\e\(J) | ($RE{ISO_ASC}) | ($RE{JIS_KANA}) | )
88 ([^\e]*)
89 }x;
90  
91 0 ▶sub cat_decode { # ($obj, $dst, $src, $pos, $trm, $chk)
Subroutine cat_decode: not called CC=14 SCAR=52.2
Pod documented
92 0 my ( $obj, undef, undef, $pos, $trm ) = @_; # currently ignores $chk
93 0 my ( $rdst, $rsrc, $rpos ) = \@_[ 1, 2, 3 ];
94 0 local ${^ENCODING};
95 1 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 0 my $opos = pos($$rsrc);
97 0 pos($$rsrc) = $pos;
98 0 ▶ while ( $$rsrc =~ /$re_scan_jis_g/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$rsrc =~ /$re_scan_jis_g/cg) 0 0 0
99 0 my ( $esc, $esc_0212, $esc_0208_1978, $esc_0201, $esc_asc, $esc_kana, $chunk ) =
100 ( $1, $2, $3, $4, $5, $6, $7 );
101  
102 0 ▶ unless ($chunk) { $esc or last; next; }
Branch: 2 branches
BranchTrueFalseTotal
unless ($chunk) 0 0 0
$esc or last 0 0 0
103
104 0 ▶ if ( $esc && !$esc_asc && !$esc_0208_1978 && !$esc_0201 ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($esc and not $esc_asc and not $esc_0208_1978 and not $esc_0201) { } 0 0 0
elsif ($esc_0208_1978) { } 0 0 0
elsif ($esc_0201) { } 0 0 0
elsif ((my $npos = index($chunk, $trm)) >= 0) { } 0 0 0
Condition0%0/9
$esc and not $esc_asc and not $esc_0208_1978 and not $esc_0201
!ll&&!rl&&r
000
$esc and not $esc_asc and not $esc_0208_1978
!ll&&!rl&&r
000
$esc and not $esc_asc
!ll&&!rl&&r
000
MC/DC0%0/4
$esc and not $esc_asc and not $esc_0208_1978 and not $esc_0201
$esc not $esc_asc not $esc_0208_1978 not $esc_0201
Truth table0%0/5
A and not(B) and not(C) and not(D)
A= $escB= not $esc_ascC= not $esc_0208_1978D= not $esc_0201
ABCDresult
0XXX0
10XX0
110X0
11100
11111
105 0 $chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
106 0 ▶ if ($esc_kana) {
Branch: 2 branches
BranchTrueFalseTotal
if ($esc_kana) { } 0 0 0
elsif ($esc_0212) { } 0 0 0
107 0 $chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
108 }
109 elsif ($esc_0212) {
110 0 $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
111 }
112 0 $chunk = Encode::decode( 'eucJP-ascii', $chunk, 0 );
113 }
114 elsif ( $esc_0208_1978 ) {
115 0 ▶ $chunk =~ s{([\x21-\x7E]{2})}{$swap1978{$1} || $1}eg;
Condition0%0/3
$swap1978{$1} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$swap1978{$1} || $1
$swap1978{$1} $1
Truth table0%0/3
A || B
A= $swap1978{$1}B= $1
ABresult
1X1
011
000
116 0 $chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
117 0 $chunk = Encode::decode( 'eucJP-ascii', $chunk, 0 );
118 }
119 elsif ( $esc_0201 ) {
120 0 $chunk =~ s/\x5C/\xA1\xEF/og;
121 0 $chunk =~ s/\x7E/\xA1\xB1/og;
122 0 $chunk = Encode::decode( 'eucJP-ascii', $chunk, 0 );
123 }
124 elsif ( ( my $npos = index( $chunk, $trm ) ) >= 0 ) {
125 0 $$rdst .= substr( $chunk, 0, $npos + length($trm) );
126 0 $$rpos += length($esc) + $npos + length($trm);
127 0 pos($$rsrc) = $opos;
128 0 return 1;
129 }
130 0 $$rdst .= $chunk;
131 0 $$rpos = pos($$rsrc);
132 }
133 0 $$rpos = pos($$rsrc);
134 0 pos($$rsrc) = $opos;
135 0 return '';
136 }
137  
138 1 1;
139 __END__
↑ Summary EUCJPASCII.c »