1 package Encode::Tcl::Extended;
3 our $VERSION = do { my @r = (q$Revision: 0.90 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
5 use base 'Encode::Encoding';
11 my ($obj,$fh,$name) = @_;
12 my(%tbl, $enc, %ssc, @key);
15 next unless /^(\S+)\s+(.*)$/;
16 my ($key,$val) = ($1,$2);
17 $val =~ s/\{(.*?)\}/$1/;
18 $val =~ s/\\x([0-9a-f]{2})/chr(hex($1))/ge;
20 if($enc = Encode->getEncoding($key))
23 $tbl{$val} = ref($enc) eq 'Encode::Tcl' ? $enc->loadEncoding : $enc;
24 $ssc{$val} = substr($val,1) if $val =~ /^>/;
31 $obj->{'SSC'} = \%ssc; # single shift char
32 $obj->{'Tbl'} = \%tbl; # encoding tables
33 $obj->{'Key'} = \@key; # keys of table hash
39 my ($obj,$str,$chk) = @_;
40 my $name = $obj->{'Name'};
41 my $tbl = $obj->{'Tbl'};
42 my $ssc = $obj->{'SSC'};
43 my $cur = ''; # current state
47 my $cc = substr($str,0,1,'');
49 if(!$cur && $ch > 0x7F)
52 $cur .= $cc, next if $ssc->{$cur.$cc};
56 if(ref($tbl->{$cur}) ne 'Encode::Tcl::Table')
58 $uni .= $tbl->{$cur}->decode($cc);
62 my $rep = $tbl->{$cur}->{'Rep'};
63 my $touni = $tbl->{$cur}->{'ToUni'};
65 if (&$rep($ch) eq 'C')
67 $x = $touni->[0][$ch];
73 $str = $cc; # split leading byte
76 my $c2 = substr($str,0,1,'');
78 $x = $touni->[$ch][0x80 ^ ord($c2)];
82 Encode::Tcl::no_map_in_decode($name, $cc.$str);
90 $_[1] = $cur ne '' ? $cur.$str : $str;
97 my ($obj,$uni,$chk) = @_;
98 my $name = $obj->{'Name'};
99 my $tbl = $obj->{'Tbl'};
100 my $ssc = $obj->{'SSC'};
101 my $key = $obj->{'Key'};
107 my $ch = substr($uni,0,1,'');
109 foreach my $k (@$key)
111 $x = ref($tbl->{$k}) ne 'Encode::Tcl::Table'
113 ? $tbl->{$k}->encode(chr(0x80 ^ ord $ch),1)
114 : $tbl->{$k}->encode($ch,1)
115 : $tbl->{$k}->{FmUni}->{$ch};
116 $cur = $k, last if defined $x;
122 Encode::Tcl::no_map_in_encode(ord($ch), $name)
126 if(ref($tbl->{$cur}) eq 'Encode::Tcl::Table')
128 my $def = $tbl->{$cur}->{'Def'};
129 my $rep = $tbl->{$cur}->{'Rep'};
133 ? $r eq 'C' ? 0x80 ^ $x : 0x8080 ^ $x
136 $str .= $ssc->{$cur} if defined $ssc->{$cur};
139 $_[1] = $uni if $chk;
147 Encode::Tcl::Extended - Tcl EUC encodings
155 This module is used internally by Encode::Tcl
156 and handles type X of Tcl encodings (a Perl extenstion).
158 Only F<euc-jp-0212.enc> belongs to type X.
159 This is a variant of EUC-JP with JIS X 0212 in G3.
160 If another Encode:: module would support the above encoding,
161 this module should be removed.