line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IOas::CP932NEC; |
2
|
|
|
|
|
|
|
###################################################################### |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# IOas::CP932NEC - provides CP932NEC I/O subroutines for UTF-8 script |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# http://search.cpan.org/dist/IOas-CP932NEC/ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright (c) 2019 INABA Hitoshi in a CPAN |
9
|
|
|
|
|
|
|
###################################################################### |
10
|
|
|
|
|
|
|
|
11
|
12
|
|
|
12
|
|
38250
|
use 5.00503; # Galapagos Consensus 1998 for primetools |
|
12
|
|
|
|
|
93
|
|
12
|
|
|
|
|
|
|
# use 5.008001; # Lancaster Consensus 2013 for toolchains |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.08'; |
15
|
|
|
|
|
|
|
$VERSION = $VERSION; |
16
|
|
|
|
|
|
|
|
17
|
12
|
|
|
12
|
|
59
|
use strict; |
|
12
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
397
|
|
18
|
12
|
50
|
|
12
|
|
237
|
BEGIN { $INC{'warnings.pm'} = '' if $] < 5.006 }; use warnings; $^W=1; |
|
12
|
|
|
12
|
|
53
|
|
|
12
|
|
|
|
|
36
|
|
|
12
|
|
|
|
|
558
|
|
19
|
12
|
|
|
12
|
|
4897
|
use Symbol (); |
|
12
|
|
|
|
|
8167
|
|
|
12
|
|
|
|
|
247
|
|
20
|
12
|
|
|
12
|
|
75789
|
use Jacode4e::RoundTrip; # pmake.bat makes META.yml, META.json and Makefile.PL by /^use / |
|
12
|
|
|
|
|
29024215
|
|
|
12
|
|
|
|
|
14556
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
23
|
|
|
|
|
|
|
# import |
24
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub import { |
27
|
12
|
|
|
12
|
|
110
|
my $self = shift @_; |
28
|
12
|
50
|
33
|
|
|
440
|
if (defined($_[0]) and ($_[0] =~ /\A[0123456789]/)) { |
29
|
0
|
0
|
|
|
|
0
|
if ($_[0] != $IOas::CP932NEC::VERSION) { |
30
|
0
|
|
|
|
|
0
|
my($package,$filename,$line) = caller; |
31
|
0
|
|
|
|
|
0
|
die "$filename requires @{[__PACKAGE__]} $_[0], this is version $IOas::CP932NEC::VERSION, stopped at $filename line $line.\n"; |
|
0
|
|
|
|
|
0
|
|
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
0
|
shift @_; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
# autodetect I/O encoding from package name |
39
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
(my $__package__ = __PACKAGE__) =~ s/utf81/utf8.1/i; |
42
|
|
|
|
|
|
|
my $io_encoding = lc((split /::/, $__package__)[-1]); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _io_input ($) { |
45
|
50
|
|
|
50
|
|
100
|
my($s) = @_; |
46
|
50
|
|
|
|
|
132
|
Jacode4e::RoundTrip::convert(\$s, 'utf8.1', $io_encoding); |
47
|
50
|
|
|
|
|
6874
|
return $s; |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _io_output ($) { |
51
|
262
|
|
|
262
|
|
452
|
my($s) = @_; |
52
|
262
|
|
|
|
|
1303
|
Jacode4e::RoundTrip::convert(\$s, $io_encoding, 'utf8.1', { |
53
|
|
|
|
|
|
|
'OVERRIDE_MAPPING' => { |
54
|
|
|
|
|
|
|
"\xE2\x80\x95" => "\x81\x5C", |
55
|
|
|
|
|
|
|
"\xE2\x88\xA5" => "\x81\x61", |
56
|
|
|
|
|
|
|
"\xEF\xBC\x8D" => "\x81\x7C", |
57
|
|
|
|
|
|
|
"\xE2\x80\x94" => "\x81\x5C", |
58
|
|
|
|
|
|
|
"\xE2\x80\x96" => "\x81\x61", |
59
|
|
|
|
|
|
|
"\xE2\x88\x92" => "\x81\x7C", |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
}); |
62
|
262
|
|
|
|
|
23761
|
return $s; |
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
66
|
|
|
|
|
|
|
# Octet Length as I/O Encoding |
67
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub length (;$) { |
70
|
18
|
100
|
|
18
|
0
|
530
|
return CORE::length _io_output(@_ ? $_[0] : $_); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub sprintf ($@) { |
74
|
10
|
|
|
10
|
0
|
734
|
my($format, @list) = map { _io_output($_) } @_; |
|
19
|
|
|
|
|
32
|
|
75
|
10
|
|
|
|
|
144
|
return _io_input(CORE::sprintf($format, @list)); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub substr ($$;$$) { |
79
|
6
|
100
|
|
6
|
0
|
1141
|
if (@_ == 4) { |
|
|
100
|
|
|
|
|
|
80
|
2
|
|
|
|
|
6
|
my $expr = _io_output($_[0]); |
81
|
2
|
|
|
|
|
5
|
my $substr = CORE::substr($expr, $_[1], $_[2], _io_output($_[3])); |
82
|
2
|
|
|
|
|
4
|
$_[0] = _io_input($expr); |
83
|
2
|
|
|
|
|
5
|
return _io_input($substr); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif (@_ == 3) { |
86
|
2
|
|
|
|
|
7
|
return _io_input(CORE::substr(_io_output($_[0]), $_[1], $_[2])); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
2
|
|
|
|
|
7
|
return _io_input(CORE::substr(_io_output($_[0]), $_[1])); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
94
|
|
|
|
|
|
|
# String Comparison as I/O Encoding |
95
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
96
|
|
|
|
|
|
|
|
97
|
20
|
|
|
20
|
0
|
672
|
sub cmp ($$) { _io_output($_[0]) cmp _io_output($_[1]) } |
98
|
10
|
|
|
10
|
0
|
13957
|
sub eq ($$) { _io_output($_[0]) eq _io_output($_[1]) } |
99
|
10
|
|
|
10
|
0
|
229
|
sub ne ($$) { _io_output($_[0]) ne _io_output($_[1]) } |
100
|
10
|
|
|
10
|
0
|
218
|
sub ge ($$) { _io_output($_[0]) ge _io_output($_[1]) } |
101
|
10
|
|
|
10
|
0
|
305
|
sub gt ($$) { _io_output($_[0]) gt _io_output($_[1]) } |
102
|
10
|
|
|
10
|
0
|
282
|
sub le ($$) { _io_output($_[0]) le _io_output($_[1]) } |
103
|
10
|
|
|
10
|
0
|
745
|
sub lt ($$) { _io_output($_[0]) lt _io_output($_[1]) } |
104
|
|
|
|
|
|
|
sub sort (@) { |
105
|
9
|
|
|
|
|
17
|
map { $_->[0] } |
106
|
21
|
|
|
|
|
26
|
CORE::sort { $a->[1] cmp $b->[1] } |
107
|
1
|
|
|
1
|
0
|
633
|
map { [ $_, _io_output($_) ] } |
|
9
|
|
|
|
|
18
|
|
108
|
|
|
|
|
|
|
@_; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
112
|
|
|
|
|
|
|
# Encoding Convert on I/O Operations |
113
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub getc (;*) { |
116
|
4
|
100
|
|
4
|
0
|
1648
|
my $fh = @_ ? Symbol::qualify_to_ref($_[0],caller()) : \*STDIN; |
117
|
4
|
|
|
|
|
87
|
my $octet = CORE::getc($fh); |
118
|
4
|
50
|
|
|
|
28
|
if ($io_encoding =~ /^(?:cp932nec|cp932|cp932ibm|cp932nec|sjis2004)$/) { |
119
|
4
|
50
|
|
|
|
15
|
if ($octet =~ /\A[\x81-\x9F\xE0-\xFC]\z/) { |
120
|
4
|
|
|
|
|
10
|
$octet .= CORE::getc($fh); |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# ('cp932'.'x') to escape from build system |
123
|
4
|
50
|
33
|
|
|
13
|
if (($io_encoding eq ('cp932'.'x')) and ($octet eq "\x9C\x5A")) { |
124
|
0
|
|
|
|
|
0
|
$octet .= CORE::getc($fh); |
125
|
0
|
|
|
|
|
0
|
$octet .= CORE::getc($fh); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
4
|
|
|
|
|
9
|
return _io_input($octet); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub readline (;*) { |
133
|
24
|
100
|
|
24
|
0
|
2843
|
my $fh = @_ ? Symbol::qualify_to_ref($_[0],caller()) : \*ARGV; |
134
|
24
|
100
|
|
|
|
666
|
return wantarray ? map { _io_input($_) } <$fh> : _io_input(<$fh>); |
|
6
|
|
|
|
|
11
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub print (;*@) { |
138
|
10
|
100
|
100
|
10
|
0
|
3298
|
my $fh = ((@_ >= 1) and defined(fileno(Symbol::qualify_to_ref($_[0],caller())))) ? Symbol::qualify_to_ref(shift,caller()) : Symbol::qualify_to_ref(select,caller()); |
139
|
10
|
100
|
|
|
|
295
|
return CORE::print {$fh} (map { _io_output($_) } (@_ ? @_ : $_)); |
|
10
|
|
|
|
|
25
|
|
|
10
|
|
|
|
|
18
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub printf (;*@) { |
143
|
20
|
100
|
66
|
20
|
0
|
4404
|
my $fh = ((@_ >= 1) and defined(fileno(Symbol::qualify_to_ref($_[0],caller())))) ? Symbol::qualify_to_ref(shift,caller()) : Symbol::qualify_to_ref(select,caller()); |
144
|
20
|
50
|
|
|
|
631
|
my($format, @list) = map { _io_output($_) } (@_ ? @_ : $_); |
|
38
|
|
|
|
|
63
|
|
145
|
20
|
|
|
|
|
29
|
return CORE::printf {$fh} ($format, @list); |
|
20
|
|
|
|
|
127
|
|
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
__END__ |