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