1 package Encode::JP::JIS7;
4 our $VERSION = do { my @r = (q$Revision: 1.7 $ =~ /\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 sub name { shift->{'Name'} }
22 sub new_sequence { $_[0] }
27 eval{ require PerlIO::encoding };
31 return (PerlIO::encoding->VERSION >= 0.03);
35 use Encode::CJKConstants qw(:all);
40 # decode is identical for all 2022 variants
45 my ($obj, $str, $chk) = @_;
48 $str =~ s/([^\x00-\x7f].*)$//so;
51 $residue .= jis_euc(\$str);
52 $_[1] = $residue if $chk;
53 return Encode::decode('euc-jp', $str, FB_PERLQQ);
62 require Encode::JP::H2Z;
63 my ($obj, $utf8, $chk) = @_;
64 # empty the input string in the stack so perlio is ok
66 my ($h2z, $jis0212) = @$obj{qw(h2z jis0212)};
67 my $octet = Encode::encode('euc-jp', $utf8, FB_PERLQQ) ;
68 $h2z and &Encode::JP::H2Z::h2z(\$octet);
69 euc_jis(\$octet, $jis0212);
79 ($RE{JIS_0212}|$RE{JIS_0208}|$RE{ISO_ASC}|$RE{JIS_KANA})
83 my ($esc, $chunk) = ($1, $2);
84 if ($esc !~ /$RE{ISO_ASC}/o) {
85 $chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
86 if ($esc =~ /$RE{JIS_KANA}/o) {
87 $chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
89 elsif ($esc =~ /$RE{JIS_0212}/o) {
90 $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
95 my ($residue) = ($$r_str =~ s/(\e.*)$//so);
100 no warnings qw(uninitialized);
104 ((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+)
108 ( $chunk =~ tr/\x8E//d ) ? $ESC{KANA} :
109 ( $chunk =~ tr/\x8F//d ) ? $ESC{JIS_0212} :
111 if ($esc eq $ESC{JIS_0212} && !$jis0212){
113 $chunk =~ tr/\xA1-\xFE/\x3F/;
115 $chunk =~ tr/\xA1-\xFE/\x21-\x7E/;
117 $esc . $chunk . $ESC{ASC};
121 (\Q$ESC{KANA}\E|\Q$ESC{JIS_0212}\E|\Q$ESC{JIS_0208}\E)/$1/gox;
131 Encode::JP::JIS7 -- internally used by Encode::JP