Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / lib / 5.8.0 / Encode / JP / JIS7.pm
CommitLineData
86530b38
AT
1package Encode::JP::JIS7;
2use strict;
3
4our $VERSION = do { my @r = (q$Revision: 1.8 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
5
6use Encode qw(:fallbacks);
7
8for 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;
11
12 $Encode::Encoding{$name} =
13 bless {
14 Name => $name,
15 h2z => $h2z,
16 jis0212 => $jis0212,
17 } => __PACKAGE__;
18}
19
20use base qw(Encode::Encoding);
21
22# we override this to 1 so PerlIO works
23sub needs_lines { 1 }
24
25use Encode::CJKConstants qw(:all);
26
27our $DEBUG = 0;
28
29#
30# decode is identical for all 2022 variants
31#
32
33sub decode($$;$)
34{
35 my ($obj, $str, $chk) = @_;
36 my $residue = '';
37 if ($chk){
38 $str =~ s/([^\x00-\x7f].*)$//so;
39 $1 and $residue = $1;
40 }
41 $residue .= jis_euc(\$str);
42 $_[1] = $residue if $chk;
43 return Encode::decode('euc-jp', $str, FB_PERLQQ);
44}
45
46#
47# encode is different
48#
49
50sub encode($$;$)
51{
52 require Encode::JP::H2Z;
53 my ($obj, $utf8, $chk) = @_;
54 # empty the input string in the stack so perlio is ok
55 $_[1] = '' if $chk;
56 my ($h2z, $jis0212) = @$obj{qw(h2z jis0212)};
57 my $octet = Encode::encode('euc-jp', $utf8, FB_PERLQQ) ;
58 $h2z and &Encode::JP::H2Z::h2z(\$octet);
59 euc_jis(\$octet, $jis0212);
60 return $octet;
61}
62
63
64# JIS<->EUC
65
66sub jis_euc {
67 my $r_str = shift;
68 $$r_str =~ s(
69 ($RE{JIS_0212}|$RE{JIS_0208}|$RE{ISO_ASC}|$RE{JIS_KANA})
70 ([^\e]*)
71 )
72 {
73 my ($esc, $chunk) = ($1, $2);
74 if ($esc !~ /$RE{ISO_ASC}/o) {
75 $chunk =~ tr/\x21-\x7e/\xa1-\xfe/;
76 if ($esc =~ /$RE{JIS_KANA}/o) {
77 $chunk =~ s/([\xa1-\xdf])/\x8e$1/og;
78 }
79 elsif ($esc =~ /$RE{JIS_0212}/o) {
80 $chunk =~ s/([\xa1-\xfe][\xa1-\xfe])/\x8f$1/og;
81 }
82 }
83 $chunk;
84 }geox;
85 my ($residue) = ($$r_str =~ s/(\e.*)$//so);
86 return $residue;
87}
88
89sub euc_jis{
90 no warnings qw(uninitialized);
91 my $r_str = shift;
92 my $jis0212 = shift;
93 $$r_str =~ s{
94 ((?:$RE{EUC_C})+|(?:$RE{EUC_KANA})+|(?:$RE{EUC_0212})+)
95 }{
96 my $chunk = $1;
97 my $esc =
98 ( $chunk =~ tr/\x8E//d ) ? $ESC{KANA} :
99 ( $chunk =~ tr/\x8F//d ) ? $ESC{JIS_0212} :
100 $ESC{JIS_0208};
101 if ($esc eq $ESC{JIS_0212} && !$jis0212){
102 # fallback to '?'
103 $chunk =~ tr/\xA1-\xFE/\x3F/;
104 }else{
105 $chunk =~ tr/\xA1-\xFE/\x21-\x7E/;
106 }
107 $esc . $chunk . $ESC{ASC};
108 }geox;
109 $$r_str =~
110 s/\Q$ESC{ASC}\E
111 (\Q$ESC{KANA}\E|\Q$ESC{JIS_0212}\E|\Q$ESC{JIS_0208}\E)/$1/gox;
112 $$r_str;
113}
114
1151;
116__END__
117
118
119=head1 NAME
120
121Encode::JP::JIS7 -- internally used by Encode::JP
122
123=cut