/[suikacvs]/perl/lib/Encode/Charset.pm
Suika

Contents of /perl/lib/Encode/Charset.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Sat Oct 12 07:27:01 2002 UTC (22 years ago) by wakaba
Branch: MAIN
Changes since 1.2: +35 -4 lines
2002-10-12  Nanashi-san

	* SJIS.pm: New module.
	* SJIS/: New directory.
	(Commited by Wakaba <w@suika.fam.cx>)

1
2 =head1 NAME
3
4 Encode::Charset --- Coded Character Sets objects,
5 used by Encode::ISO2022, Encode::SJIS, and other modules.
6
7 =cut
8
9 package Encode::Charset;
10 use strict;
11 use vars qw(%CHARSET %CODING_SYSTEM $VERSION);
12 $VERSION=do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
13
14 ## --- Make initial charset definitions
15 &_make_initial_charsets;
16 sub _make_initial_charsets () {
17 for my $f (0x30..0x7E) {
18 my $F = pack 'C', $f;
19 for ('', '!', '"', '#') {
20 $CHARSET{G94}->{ $_.$F }->{dimension} = 1;
21 $CHARSET{G94}->{ $_.$F }->{chars} = 94;
22 $CHARSET{G94}->{ $_.$F }->{ucs} =
23 {'' => 0xE90940, '!' => 0xE944A0, '"' => 0xE98000, '#' => 0xE9BB60}->{ $_ }
24 + 94 * ($f-0x30);
25
26 $CHARSET{G96}->{ $_.$F }->{dimension} = 1;
27 $CHARSET{G96}->{ $_.$F }->{chars} = 96;
28 $CHARSET{G96}->{ $_.$F }->{ucs} =
29 {'' => 0xE926A0, '!' => 0xE96200, '"' => 0xE99D60, '#' => 0xE9D8C0}->{ $_ }
30 + 96 * ($f-0x30);
31
32 $CHARSET{C0}->{ $_.$F }->{dimension} = 1;
33 $CHARSET{C0}->{ $_.$F }->{chars} = 32;
34 $CHARSET{C0}->{ $_.$F }->{ucs} =
35 {'' => 0x70000000, '!' => 0x70001400,
36 '"' => 0x70002800, '#' => 0x70003C00}->{ $_ } + 32 * ($f-0x30);
37
38 $CHARSET{C1}->{ $_.$F }->{dimension} = 1;
39 $CHARSET{C1}->{ $_.$F }->{chars} = 32;
40 $CHARSET{C1}->{ $_.$F }->{ucs} =
41 {'' => 0x70000A00, '!' => 0x70001E00,
42 '"' => 0x70003200, '#' => 0x70004600}->{ $_ } + 32 * ($f-0x30);
43
44 $CHARSET{G94}->{ ' '.$_.$F }->{dimension} = 1; ## DRCS
45 $CHARSET{G94}->{ ' '.$_.$F }->{chars} = 94;
46 $CHARSET{G94}->{ ' '.$_.$F }->{ucs} =
47 {'' => 0x70090940, '!' => 0x700944A0,
48 '"' => 0x70098000, '#' => 0x7009BB60}->{ $_ } + 94 * ($f-0x30);
49
50 $CHARSET{G96}->{ ' '.$_.$F }->{dimension} = 1; ## DRCS
51 $CHARSET{G96}->{ ' '.$_.$F }->{chars} = 96;
52 $CHARSET{G96}->{ ' '.$_.$F }->{ucs} =
53 {'' => 0x700926A0, '!' => 0x70096200,
54 '"' => 0x70099D60, '#' => 0x7009D8C0}->{ $_ } + 96 * ($f-0x30);
55 }
56 }
57 for my $f (0x30..0x5F, 0x7E) {
58 my $F = pack 'C', $f;
59 for ('', '!', '"', '#', ' ') {
60 $CHARSET{G94n}->{ $_.$F }->{dimension} = 2;
61 $CHARSET{G94n}->{ $_.$F }->{chars} = 94;
62 $CHARSET{G94n}->{ $_.$F }->{ucs} =
63 ({'' => 0xE9F6C0}->{ $_ }||0) + 94*94 * ($f-0x30);
64 ## BUG: 94^n sets with I byte have no mapping area
65
66 $CHARSET{G96n}->{ $_.$F }->{dimension} = 2;
67 $CHARSET{G96n}->{ $_.$F }->{chars} = 96;
68 $CHARSET{G96n}->{ $_.$F }->{ucs} =
69 ({'' => 0xF4C000}->{ $_ }||0) + 96*96 * ($f-0x30);
70 ## BUG: 94^n DRCSes with I byte have no mapping area
71 }
72 }
73 for (0x60..0x6F) {
74 my $F = pack 'C', $_;
75 ## BUG: 9x^3 sets have no mapping area
76 for ('', '!', '"', '#', ' ') {
77 $CHARSET{G94n}->{ $_.$F }->{dimension} = 3;
78 $CHARSET{G94n}->{ $_.$F }->{chars} = 94;
79
80 $CHARSET{G96n}->{ $_.$F }->{dimension} = 3;
81 $CHARSET{G96n}->{ $_.$F }->{chars} = 96;
82 }
83 }
84 for (0x70..0x7D) {
85 my $F = pack 'C', $_;
86 ## BUG: 9x^4 sets have no mapping area
87 for ('', '!', '"', '#', ' ') {
88 $CHARSET{G94n}->{ $_.$F }->{dimension} = 4;
89 $CHARSET{G94n}->{ $_.$F }->{chars} = 94;
90
91 $CHARSET{G96n}->{ $_.$F }->{dimension} = 4;
92 $CHARSET{G96n}->{ $_.$F }->{chars} = 96;
93 }
94 }
95 for my $f (0x40..0x4E) {
96 my $F = pack 'C', $f;
97 $CHARSET{G96n}->{ ' '.$F }->{dimension} = 2;
98 $CHARSET{G96n}->{ ' '.$F }->{chars} = 96;
99 $CHARSET{G96n}->{ ' '.$F }->{ucs} = 0xF0000 + 96*96*($f-0x40);
100 ## U+F0000-U+10F7FF (private) -> ESC 02/04 02/00 <I> (04/00-04/14) (DRCS)
101 }
102
103 $CHARSET{G94}->{B}->{ucs} = 0x21; ## ASCII
104 $CHARSET{G96}->{A}->{ucs} = 0xA0; ## ISO 8859-1
105
106 $CHARSET{G94n}->{'B@'}->{dimension} = 2; ## JIS X 0208-1990
107 $CHARSET{G94n}->{'B@'}->{chars} = 94;
108 $CHARSET{G94n}->{'B@'}->{ucs} = 0xE9F6C0 + 94*94*79;
109
110 ## SJIS G3 mapping (JIS X 0213:2000 plane 2)
111 $CHARSET{G94n}->{"\x50"}->{Csjis_kuE} = { # ku - 1
112 0xF0 => 7, 0xF1 => 3, 0xF2 => 11, 0xF3 => 13, 0xF4 => 77,
113 0xF5 => 79, 0xF6 => 81, 0xF7 => 83, 0xF8 => 85, 0xF9 => 87,
114 0xFA => 89, 0xFB => 91, 0xFC => 93,
115 };
116 $CHARSET{G94n}->{"\x50"}->{Csjis_kuO} = { # ku - 1
117 0xF0 => 0, 0xF1 => 2, 0xF2 => 4, 0xF3 => 12, 0xF4 => 14,
118 0xF5 => 78, 0xF6 => 80, 0xF7 => 82, 0xF8 => 84, 0xF9 => 86,
119 0xFA => 88, 0xFB => 90, 0xFC => 92,
120 };
121 $CHARSET{G94n}->{"\x50"}->{Csjis_first} = { reverse (
122 %{ $CHARSET{G94n}->{"\x50"}->{Csjis_kuE} },
123 %{ $CHARSET{G94n}->{"\x50"}->{Csjis_kuO} },
124 )};
125
126 ## -- Control character sets
127 $CHARSET{C0}->{'@'}->{ucs} = 0x00; ## ISO/IEC 6429 C0
128 for ("\x40", "\x43", "\x44", "\x45", "\x46", "\x49", "\x4A", "\x4B", "\x4C") {
129 $CHARSET{C0}->{$_}->{C_LS0} = "\x0F";
130 $CHARSET{C0}->{$_}->{C_LS1} = "\x0E";
131 $CHARSET{C0}->{$_}->{r_LS0} = '\x0F';
132 $CHARSET{C0}->{$_}->{r_LS1} = '\x0E';
133 }
134 for ("\x40", "\x44", "\x45", "\x46", "\x48", "\x4C") {
135 $CHARSET{C0}->{$_}->{reset_all} = {"\x0A" => 1, "\x0B" => 1,
136 "\x0C" => 1, "\x0D" => 1};
137 }
138 $CHARSET{C0}->{"\x43"}->{reset_all} = {"\x0A" => 1};
139 $CHARSET{C0}->{"\x44"}->{C_SS2} = "\x1C";
140 $CHARSET{C0}->{"\x44"}->{r_SS2} = '\x1C';
141 for ("\x45", "\x49", "\x4A", "\x4B") {
142 $CHARSET{C0}->{$_}->{C_SS2} = "\x19";
143 $CHARSET{C0}->{$_}->{C_SS3} = "\x1D";
144 $CHARSET{C0}->{$_}->{r_SS2} = '\x19';
145 $CHARSET{C0}->{$_}->{r_SS3} = '\x1D';
146 }
147 $CHARSET{C0}->{"\x4C"}->{C_SS2} = "\x19";
148 $CHARSET{C0}->{"\x4C"}->{r_SS2} = '\x19';
149
150 $CHARSET{C1}->{'64291991C1'}->{dimension} = 1; ## ISO/IEC 6429:1991 C1
151 $CHARSET{C1}->{'64291991C1'}->{chars} = 32;
152 $CHARSET{C1}->{'64291991C1'}->{ucs} = 0x80;
153 for ("\x43", "\x45", "\x47", '64291991C1') {
154 $CHARSET{C1}->{$_}->{C_SS2} = "\x8E";
155 $CHARSET{C1}->{$_}->{C_SS3} = "\x8F";
156 $CHARSET{C1}->{$_}->{r_SS2} = '\x8E';
157 $CHARSET{C1}->{$_}->{r_SS3} = '\x8F';
158 $CHARSET{C1}->{$_}->{r_SS2_ESC} = '\x1B\x4E';
159 $CHARSET{C1}->{$_}->{r_SS3_ESC} = '\x1B\x4F';
160 }
161 for ("\x43", '64291991C1') {
162 $CHARSET{C1}->{$_}->{r_CSI} = '\x9B';
163 $CHARSET{C1}->{$_}->{r_CSI_ESC} = '\x1B\x5B';
164 $CHARSET{C1}->{$_}->{r_DCS} = '\x90';
165 $CHARSET{C1}->{$_}->{r_ST} = '\x9C';
166 $CHARSET{C1}->{$_}->{r_OSC} = '\x9D';
167 $CHARSET{C1}->{$_}->{r_PM} = '\x9E';
168 $CHARSET{C1}->{$_}->{r_APC} = '\x9F';
169 $CHARSET{C1}->{$_}->{reset_all} = {"\x85"=>1, "\x90"=>1,
170 "\x9C"=>1, "\x9D"=>1, "\x9E"=>1, "\x9F"=>1};
171 }
172 $CHARSET{C1}->{'64291991C1'}->{r_SCI} = '\x9A';
173
174 $CHARSET{single_control}->{Fs} ={ucs => 0x70005000, chars => 32, dimension => 1};
175 $CHARSET{single_control}->{'3F'} ={ucs => 0x70005020, chars => 80, dimension => 1};
176 $CHARSET{single_control}->{'3F!'}={ucs => 0x70005070, chars => 80, dimension => 1};
177 $CHARSET{single_control}->{'3F"'}={ucs => 0x700050C0, chars => 80, dimension => 1};
178 $CHARSET{single_control}->{'3F#'}={ucs => 0x70005110, chars => 80, dimension => 1};
179 }
180
181 &make_initial_coding_system;
182 sub make_initial_coding_system {
183 for (0x30..0x7E) {
184 my $F = chr $_;
185 $CODING_SYSTEM{$F} = {};
186 $CODING_SYSTEM{"\x2F".$F} = {reset_state => 1};
187 }
188 $CODING_SYSTEM{Csjis} = {perl_name => 'shiftjis'};
189 }
190
191 sub make_charset (%) {
192 my %set = @_;
193 my $setid = qq($set{I}$set{F}$set{revision});
194 my $settype = $set{type} || 'G94';
195 delete $set{type}, $set{I}, $set{F}, $set{revision};
196 $CHARSET{ $settype }->{ $setid } = \%set;
197 }
198
199 ## Make a new ISO/IEC 2022-buffers object with default status
200 sub new_object {
201 my %C;
202 $C{bit} = 8;
203 $C{coding_system} = $CODING_SYSTEM{"\x40"}; ## ISO/IEC 2022
204 $C{CL} = 'C0'; $C{CR} = 'C1'; $C{ESC_Fe} = 'C1';
205 $C{C0} = $CHARSET{C0}->{"\x40"}; ## ISO/IEC 6429:1991 C0
206 $C{C1} = $CHARSET{C1}->{'64291991C1'}; ## ISO/IEC 6429:1991 C1
207 $C{GL} = 'G0'; $C{GR} = 'G1';
208 $C{G0} = $CHARSET{G94}->{"\x42"}; ## ISO/IEC 646:1991 IRV
209 #$C{G1} = $CHARSET{G96}->{"\x41"}; ## ISO/IEC 8859-1 GR
210 $C{G1} = $CHARSET{G94}->{"\x7E"}; ## empty set
211 $C{G2} = $CHARSET{G94}->{"\x7E"}; ## empty set
212 $C{G3} = $CHARSET{G94}->{"\x7E"}; ## empty set
213 $C{option} = {
214 C1invoke_to_right => 0, ## C1 invoked to: (0: ESC Fe, 1: CR)
215 G94n_designate_long => 0, ## (1: ESC 02/04 02/08 04/00..02)
216 designate_to => { ## Designated G buffer (-1: not be outputed)
217 C0 => {
218 default => 0,
219 },
220 C1 => {
221 default => 1,
222 },
223 G94 => {
224 "\x42" => 0,
225 default => 0,
226 },
227 G96 => {
228 default => 1,
229 },
230 G94n => {
231 default => 0,
232 },
233 G96n => {
234 default => 1,
235 },
236 coding_system => {
237 default => -1,
238 },
239 },
240 Ginvoke_by_single_shift => [0,0,0,0], ## Invoked by SS
241 Ginvoke_to_left => [1,1,1,1], ## Which invoked to? (1: L, 0: R)
242 private_set => { ## Private set vs Final byte
243 C0 => [],
244 C1 => [],
245 G94 => [],
246 G94n => [[],[],[],[],[]],
247 G96 => [],
248 #G96n => [], ## (not implemented)
249 U96n => [], ## mule-unicode sets
250 XC1 => {
251 '64291991C1' => undef, ## ISO/IEC 6429:1991 C1
252 },
253 },
254 reset => { ## Reset status at top of line
255 Gdesignation => "\x42", ## F of designation or 0
256 Ginvoke => 1,
257 },
258 undef_char => ["\x3F", {type => 'G94', charset => 'B'}],
259 use_revision => 1, ## Output IRR
260 };
261 ## Special code area (such as 0xFD-0xFF of sjis'es)
262 $C{Gsmap} = {"\xA0" => "\x{F8F0}", "\xFD" => "\x{F8F1}", "\xFE" => "\x{F8F2}", "\xFF" => "\x{F8F3}"};
263 $C{GsmapR} = {}; ## Reversed table
264 \%C;
265 }
266
267 sub new_object_sjis {
268 my $C = new_object;
269 $C->{coding_system} = $CODING_SYSTEM{Csjis};
270 $C->{CR} = undef;
271 $C->{GR} = 'G2'; ## 0xA1-0xDF
272 #$C->{G0} = $CHARSET{G94}->{J}; ## JIS X 0201:1997 Latin
273 $C->{G1} = $CHARSET{G94n}->{'B@'}; ## JIS X 0208:1997
274 $C->{G2} = $CHARSET{G94}->{I}; ## JIS X 0201:1997 Katakana
275 $C->{G3} = $CHARSET{G94n}->{"\x50"}; ## JIS X 0213:2000 plane 2
276 $C;
277 }
278
279 1;
280 __END__
281
282 =head1 AUTHORS
283
284 Nanashi-san
285
286 Wakaba <w@suika.fam.cx>
287
288 =head1 LICENSE
289
290 Copyright 2002 AUTHORS
291
292 This library is free software; you can redistribute it
293 and/or modify it under the same terms as Perl itself.
294
295 =cut
296
297 # $Date: 2002/09/21 01:34:08 $
298 ### Charset.pm ends here

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24