1 package Encode::JP::JIS7;
4 our $VERSION = do { my @r = (q$Revision: 1.11 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
6 use Encode qw(:fallbacks);
8 for my $name ('7bit-jis', 'iso-2022-jp', 'iso-2022-jp-1'){
9 my $h2z = ($name eq '7bit-jis') ? 0 : 1;
10 my $jis0212 = ($name eq 'iso-2022-jp') ? 0 : 1;
12 $Encode::Encoding{$name} =
20 use base qw(Encode::Encoding);
22 # we override this to 1 so PerlIO works
25 use Encode::CJKConstants qw(:all);
30 # decode is identical for all 2022 variants
35 my ($obj, $str, $chk) = @_;
38 $str =~ s/([^\x00-\x7f].*)$//so and $residue = $1;
40 $residue .= jis_euc(\$str);
41 $_[1] = $residue if $chk;
42 return Encode::decode('euc-jp', $str, FB_PERLQQ);
51 require Encode::JP::H2Z;
52 my ($obj, $utf8, $chk) = @_;
53 # empty the input string in the stack so perlio is ok
55 my ($h2z, $jis0212) = @$obj{qw(h2z jis0212)};
56 my $octet = Encode::encode('euc-jp', $utf8, FB_PERLQQ) ;
57 $h2z and &Encode::JP::H2Z::h2z(\$octet);
58 euc_jis(\$octet, $jis0212);
65 my $re_scan_jis_g = qr{
66 \G ( ($RE{JIS_0212}) | $RE{JIS_0208} |
67 ($RE{ISO_ASC}) | ($RE{JIS_KANA}) | )
70 sub cat_decode { # ($obj, $dst, $src, $pos, $trm, $chk)
71 my ($obj, undef, undef, $pos, $trm) = @_; # currently ignores $chk
72 my ($rdst, $rsrc, $rpos) = \@_[1,2,3];
75 my $opos = pos($$rsrc);
77 while ($$rsrc =~ /$re_scan_jis_g/gc) {
78 my ($esc, $esc_0212, $esc_asc, $esc_kana, $chunk) =
81 unless ($chunk) { $esc or last; next; }
83 if ($esc && !$esc_asc) {
84 $chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
86 $chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
88 $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
90 $chunk = Encode::decode('euc-jp', $chunk, 0);
92 elsif ((my $npos = index($chunk, $trm)) >= 0) {
93 $$rdst .= substr($chunk, 0, $npos + length($trm));
94 $$rpos += length($esc) + $npos + length($trm);
101 $$rpos = pos($$rsrc);
107 my $re_scan_jis = qr{
108 (?:($RE{JIS_0212})|$RE{JIS_0208}|($RE{ISO_ASC})|($RE{JIS_KANA}))([^\e]*)
114 $$r_str =~ s($re_scan_jis)
116 my ($esc_0212, $esc_asc, $esc_kana, $chunk) =
119 $chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
121 $chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
124 $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
129 my ($residue) = ($$r_str =~ s/(\e.*)$//so);
134 no warnings qw(uninitialized);
138 ((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+)
142 ( $chunk =~ tr/\x8E//d ) ? $ESC{KANA} :
143 ( $chunk =~ tr/\x8F//d ) ? $ESC{JIS_0212} :
145 if ($esc eq $ESC{JIS_0212} && !$jis0212){
147 $chunk =~ tr/\xA1-\xFE/\x3F/;
149 $chunk =~ tr/\xA1-\xFE/\x21-\x7E/;
151 $esc . $chunk . $ESC{ASC};
155 (\Q$ESC{KANA}\E|\Q$ESC{JIS_0212}\E|\Q$ESC{JIS_0208}\E)/$1/gox;
165 Encode::JP::JIS7 -- internally used by Encode::JP