/[suikacvs]/markup/html/whatpm/Whatpm/Charset/DecodeHandle.pm
Suika

Contents of /markup/html/whatpm/Whatpm/Charset/DecodeHandle.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Sat May 17 12:29:24 2008 UTC (18 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +40 -18 lines
++ whatpm/Whatpm/ChangeLog	17 May 2008 12:28:47 -0000
	* HTML.pm.src (parse_byte_string): Use streaming decoder
	rather than converting the whole byte string and then parsing.
	Propagate errors in character encoding layer.
	(get_next_token): Precise error reporting for |bare stago| error.

2008-05-17  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/Charset/ChangeLog	17 May 2008 12:29:09 -0000
2008-05-17  Wakaba  <wakaba@suika.fam.cx>

	* DecodeHandle.pm (ByteBuffer): New class.

1 package Whatpm::Charset::DecodeHandle;
2 use strict;
3
4 my $XML_AUTO_CHARSET = q<http://suika.fam.cx/www/2006/03/xml-entity/>;
5 my $IANA_CHARSET = q<urn:x-suika-fam-cx:charset:>;
6 my $PERL_CHARSET = q<http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.>;
7 my $XML_CHARSET = q<http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.>;
8
9 ## ->create_decode_handle ($charset_uri, $byte_stream, $onerror)
10 sub create_decode_handle ($$$;$) {
11 my $csdef = $Whatpm::Charset::CharsetDef->{$_[1]};
12 my $obj = {
13 character_queue => [],
14 filehandle => $_[2],
15 charset => $_[1],
16 byte_buffer => '',
17 onerror => $_[3] || sub {},
18 };
19 if ($csdef->{uri}->{$XML_AUTO_CHARSET} or
20 $obj->{charset} eq $XML_AUTO_CHARSET) {
21 my $b = ''; # UTF-8 w/o BOM
22 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
23 $obj->{input_encoding} = 'UTF-8';
24 if (read $obj->{filehandle}, $b, 256) {
25 no warnings "substr";
26 no warnings "uninitialized";
27 if (substr ($b, 0, 1) eq "<") {
28 if (substr ($b, 1, 1) eq "?") { # ASCII8
29 if ($b =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
30 encoding\s*=\s*["']([^"']*)/x) {
31 $obj->{input_encoding} = $1;
32 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
33 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
34 if (not $csdef->{ascii8} or $csdef->{bom_required}) {
35 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
36 charset_uri => $uri,
37 charset_name => $obj->{input_encoding});
38 }
39 } else {
40 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
41 $obj->{input_encoding} = 'UTF-8';
42 }
43 if (defined $csdef->{no_bom_variant}) {
44 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant}};
45 }
46 } elsif (substr ($b, 1, 1) eq "\x00") {
47 if (substr ($b, 2, 2) eq "?\x00") { # ASCII16LE
48 my $c = $b; $c =~ tr/\x00//d;
49 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
50 encoding\s*=\s*["']([^"']*)/x) {
51 $obj->{input_encoding} = $1;
52 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
53 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
54 if (not $csdef->{ascii16} or $csdef->{ascii16be} or
55 $csdef->{bom_required}) {
56 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
57 charset_uri => $uri,
58 charset_name => $obj->{input_encoding});
59 }
60 } else {
61 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
62 $obj->{input_encoding} = 'UTF-8';
63 }
64 if (defined $csdef->{no_bom_variant16le}) {
65 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant16le}};
66 }
67 } elsif (substr ($b, 2, 2) eq "\x00\x00") { # ASCII32Endian4321
68 my $c = $b; $c =~ tr/\x00//d;
69 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
70 encoding\s*=\s*["']([^"']*)/x) {
71 $obj->{input_encoding} = $1;
72 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
73 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
74 if (not $csdef->{ascii32} or
75 $csdef->{ascii32endian1234} or
76 $csdef->{ascii32endian2143} or
77 $csdef->{ascii32endian3412} or
78 $csdef->{bom_required}) {
79 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
80 charset_uri => $uri,
81 charset_name => $obj->{input_encoding});
82 }
83 } else {
84 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
85 $obj->{input_encoding} = 'UTF-8';
86 }
87 if (defined $csdef->{no_bom_variant32endian4321}) {
88 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian4321}};
89 }
90 }
91 }
92 } elsif (substr ($b, 0, 3) eq "\xEF\xBB\xBF") { # UTF8
93 $obj->{has_bom} = 1;
94 substr ($b, 0, 3) = '';
95 my $c = $b;
96 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
97 encoding\s*=\s*["']([^"']*)/x) {
98 $obj->{input_encoding} = $1;
99 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
100 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
101 if (not $csdef->{utf8_encoding_scheme} or
102 not $csdef->{bom_allowed}) {
103 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
104 charset_uri => $uri,
105 charset_name => $obj->{input_encoding});
106 }
107 } else {
108 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
109 $obj->{input_encoding} = 'UTF-8';
110 }
111 if (defined $csdef->{no_bom_variant}) {
112 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant}};
113 }
114 } elsif (substr ($b, 0, 2) eq "\x00<") {
115 if (substr ($b, 2, 2) eq "\x00?") { # ASCII16BE
116 my $c = $b; $c =~ tr/\x00//d;
117 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
118 encoding\s*=\s*["']([^"']*)/x) {
119 $obj->{input_encoding} = $1;
120 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
121 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
122 if (not $csdef->{ascii16} or $csdef->{ascii16le} or
123 $csdef->{bom_required}) {
124 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
125 charset_uri => $uri,
126 charset_name => $obj->{input_encoding});
127 }
128 } else {
129 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
130 $obj->{input_encoding} = 'UTF-8';
131 }
132 if (defined $csdef->{no_bom_variant16be}) {
133 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant16be}};
134 }
135 } elsif (substr ($b, 2, 2) eq "\x00\x00") { # ASCII32Endian3412
136 my $c = $b; $c =~ tr/\x00//d;
137 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
138 encoding\s*=\s*["']([^"']*)/x) {
139 $obj->{input_encoding} = $1;
140 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
141 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
142 if (not $csdef->{ascii32} or
143 $csdef->{ascii32endian1234} or
144 $csdef->{ascii32endian2143} or
145 $csdef->{ascii32endian4321} or
146 $csdef->{bom_required}) {
147 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
148 charset_uri => $uri,
149 charset_name => $obj->{input_encoding});
150 }
151 } else {
152 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
153 $obj->{input_encoding} = 'UTF-8';
154 }
155 if (defined $csdef->{no_bom_variant32endian3412}) {
156 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian3412}};
157 }
158 }
159 } elsif (substr ($b, 0, 2) eq "\xFE\xFF") {
160 if (substr ($b, 2, 2) eq "\x00<") { # ASCII16BE
161 $obj->{has_bom} = 1;
162 substr ($b, 0, 2) = '';
163 my $c = $b; $c =~ tr/\x00//d;
164 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
165 encoding\s*=\s*["']([^"']*)/x) {
166 $obj->{input_encoding} = $1;
167 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
168 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
169 if (not $csdef->{ascii16} or
170 $csdef->{ascii16le} or
171 not $csdef->{bom_allowed}) {
172 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
173 charset_uri => $uri,
174 charset_name => $obj->{input_encoding});
175 }
176 } else {
177 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16be'};
178 $obj->{input_encoding} = 'UTF-16';
179 }
180 if (defined $csdef->{no_bom_variant16be}) {
181 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant16be}};
182 }
183 } elsif (substr ($b, 2, 2) eq "\x00\x00") { # ASCII32Endian3412
184 $obj->{has_bom} = 1;
185 substr ($b, 0, 4) = '';
186 my $c = $b; $c =~ tr/\x00//d;
187 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
188 encoding\s*=\s*["']([^"']*)/x) {
189 $obj->{input_encoding} = $1;
190 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
191 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
192 if (not $csdef->{ascii32} or
193 $csdef->{ascii32endian1234} or
194 $csdef->{ascii32endian2143} or
195 $csdef->{ascii32endian4321} or
196 not $csdef->{bom_allowed}) {
197 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
198 charset_uri => $uri,
199 charset_name => $obj->{input_encoding});
200 }
201 } else {
202 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16be'};
203 $obj->{input_encoding} = 'UTF-16';
204 $obj->{byte_buffer} .= "\x00\x00";
205 }
206 if (defined $csdef->{no_bom_variant32endian3412}) {
207 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian3412}};
208 }
209 } else {
210 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16be'};
211 $obj->{input_encoding} = 'UTF-16';
212 substr ($b, 0, 2) = '';
213 $obj->{has_bom} = 1;
214 }
215 } elsif (substr ($b, 0, 2) eq "\xFF\xFE") {
216 if (substr ($b, 2, 2) eq "<\x00") { # ASCII16LE
217 $obj->{has_bom} = 1;
218 substr ($b, 0, 2) = '';
219 my $c = $b; $c =~ tr/\x00//d;
220 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
221 encoding\s*=\s*["']([^"']*)/x) {
222 $obj->{input_encoding} = $1;
223 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
224 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
225 if (not $csdef->{ascii16} or
226 $csdef->{ascii16be} or
227 not $csdef->{bom_allowed}) {
228 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
229 charset_uri => $uri,
230 charset_name => $obj->{input_encoding});
231 }
232 } else {
233 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16le'};
234 $obj->{input_encoding} = 'UTF-16';
235 }
236 if (defined $csdef->{no_bom_variant16le}) {
237 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant16le}};
238 }
239 } elsif (substr ($b, 2, 2) eq "\x00\x00") { # ASCII32Endian4321
240 $obj->{has_bom} = 1;
241 substr ($b, 0, 4) = '';
242 my $c = $b; $c =~ tr/\x00//d;
243 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
244 encoding\s*=\s*["']([^"']*)/x) {
245 $obj->{input_encoding} = $1;
246 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
247 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
248 if (not $csdef->{ascii32} or
249 $csdef->{ascii32endian1234} or
250 $csdef->{ascii32endian2143} or
251 $csdef->{ascii32endian3412} or
252 not $csdef->{bom_allowed}) {
253 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
254 charset_uri => $uri,
255 charset_name => $obj->{input_encoding});
256 }
257 } else {
258 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16le'};
259 $obj->{input_encoding} = 'UTF-16';
260 $obj->{byte_buffer} .= "\x00\x00";
261 }
262 if (defined $csdef->{no_bom_variant32endian4321}) {
263 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian4321}};
264 }
265 } else {
266 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16le'};
267 $obj->{input_encoding} = 'UTF-16';
268 substr ($b, 0, 2) = '';
269 $obj->{has_bom} = 1;
270 }
271 } elsif (substr ($b, 0, 2) eq "\x00\x00") {
272 if (substr ($b, 2, 2) eq "\x00<") { # ASCII32Endian1234
273 my $c = $b; $c =~ tr/\x00//d;
274 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
275 encoding\s*=\s*["']([^"']*)/x) {
276 $obj->{input_encoding} = $1;
277 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
278 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
279 if (not $csdef->{ascii32} or
280 $csdef->{ascii32endian2143} or
281 $csdef->{ascii32endian3412} or
282 $csdef->{ascii32endian4321} or
283 $csdef->{bom_required}) {
284 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
285 charset_uri => $uri,
286 charset_name => $obj->{input_encoding});
287 }
288 } else {
289 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
290 $obj->{input_encoding} = 'UTF-8';
291 }
292 if (defined $csdef->{no_bom_variant32endian1234}) {
293 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian1234}};
294 }
295 } elsif (substr ($b, 2, 2) eq "<\x00") { # ASCII32Endian2143
296 my $c = $b; $c =~ tr/\x00//d;
297 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
298 encoding\s*=\s*["']([^"']*)/x) {
299 $obj->{input_encoding} = $1;
300 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
301 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
302 if (not $csdef->{ascii32} or
303 $csdef->{ascii32endian1234} or
304 $csdef->{ascii32endian3412} or
305 $csdef->{ascii32endian4321} or
306 $csdef->{bom_required}) {
307 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
308 charset_uri => $uri,
309 charset_name => $obj->{input_encoding});
310 }
311 } else {
312 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
313 $obj->{input_encoding} = 'UTF-8';
314 }
315 if (defined $csdef->{no_bom_variant32endian2143}) {
316 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian2143}};
317 }
318 } elsif (substr ($b, 2, 2) eq "\xFE\xFF") { # ASCII32Endian1234
319 $obj->{has_bom} = 1;
320 substr ($b, 0, 4) = '';
321 my $c = $b; $c =~ tr/\x00//d;
322 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
323 encoding\s*=\s*["']([^"']*)/x) {
324 $obj->{input_encoding} = $1;
325 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
326 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
327 if (not $csdef->{ascii32} or
328 $csdef->{ascii32endian2143} or
329 $csdef->{ascii32endian3412} or
330 $csdef->{ascii32endian4321} or
331 $csdef->{bom_required}) {
332 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
333 charset_uri => $uri,
334 charset_name => $obj->{input_encoding});
335 }
336 } else {
337 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
338 $obj->{input_encoding} = 'UTF-8';
339 $obj->{has_bom} = 0;
340 $obj->{byte_buffer} .= "\x00\x00\xFE\xFF";
341 }
342 if (defined $csdef->{no_bom_variant32endian1234}) {
343 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian1234}};
344 }
345 } elsif (substr ($b, 2, 2) eq "\xFF\xFE") { # ASCII32Endian2143
346 $obj->{has_bom} = 1;
347 substr ($b, 0, 4) = '';
348 my $c = $b; $c =~ tr/\x00//d;
349 if ($c =~ /^<\?xml\s+(?:version\s*=\s*["'][^"']*["']\s*)?
350 encoding\s*=\s*["']([^"']*)/x) {
351 $obj->{input_encoding} = $1;
352 my $uri = name_to_uri (undef, 'xml', $obj->{input_encoding});
353 $csdef = $Whatpm::Charset::CharsetDef->{$uri};
354 if (not $csdef->{ascii32} or
355 $csdef->{ascii32endian1234} or
356 $csdef->{ascii32endian3412} or
357 $csdef->{ascii32endian4321} or
358 $csdef->{bom_required}) {
359 $obj->{onerror}->(undef, 'charset-name-mismatch-error',
360 charset_uri => $uri,
361 charset_name => $obj->{input_encoding});
362 }
363 } else {
364 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'};
365 $obj->{input_encoding} = 'UTF-8';
366 $obj->{has_bom} = 0;
367 $obj->{byte_buffer} .= "\x00\x00\xFF\xFE";
368 }
369 if (defined $csdef->{no_bom_variant32endian2143}) {
370 $csdef = $Whatpm::Charset::CharsetDef->{$csdef->{no_bom_variant32endian2143}};
371 }
372 }
373 # \x4C\x6F\xA7\x94 EBCDIC
374 } # buffer
375 $obj->{byte_buffer} .= $b;
376 } # read
377 } elsif ($csdef->{uri}->{$XML_CHARSET.'utf-8'}) {
378 ## BOM is optional.
379 my $b = '';
380 if (read $obj->{filehandle}, $b, 3) {
381 if ($b eq "\xEF\xBB\xBF") {
382 $obj->{has_bom} = 1;
383 } else {
384 $obj->{byte_buffer} .= $b;
385 }
386 }
387 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-8'}; # UTF-8 w/o BOM
388 } elsif ($csdef->{uri}->{$XML_CHARSET.'utf-16'}) {
389 ## BOM is mandated.
390 my $b = '';
391 if (read $obj->{filehandle}, $b, 2) {
392 if ($b eq "\xFE\xFF") {
393 $obj->{has_bom} = 1; # UTF-16BE w/o BOM
394 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16be'};
395 } elsif ($b eq "\xFF\xFE") {
396 $obj->{has_bom} = 1; # UTF-16LE w/o BOM
397 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16le'};
398 } else {
399 $obj->{onerror}->(undef, 'no-bom-error', charset_uri => $obj->{charset});
400 $obj->{has_bom} = 0;
401 $obj->{byte_buffer} .= $b; # UTF-16BE w/o BOM
402 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16be'};
403 }
404 } else {
405 $obj->{onerror}->(undef, 'no-bom-error', charset_uri => $obj->{charset});
406 $obj->{has_bom} = 0; # UTF-16BE w/o BOM
407 $csdef = $Whatpm::Charset::CharsetDef->{$PERL_CHARSET.'utf-16be'};
408 }
409 }
410
411 if ($csdef->{uri}->{$XML_CHARSET.'iso-2022-jp'}) {
412 $obj->{state_2440} = 'gl-jis-1997-swapped';
413 $obj->{state_2442} = 'gl-jis-1997';
414 $obj->{state} = 'state_2842';
415 require Encode::GLJIS1997Swapped;
416 require Encode::GLJIS1997;
417 if (Encode::find_encoding ($obj->{state_2440}) and
418 Encode::find_encoding ($obj->{state_2442})) {
419 return bless $obj, 'Whatpm::Charset::DecodeHandle::ISO2022JP';
420 }
421 } elsif ($csdef->{uri}->{$IANA_CHARSET.'iso-2022-jp'}) {
422 $obj->{state_2440} = 'gl-jis-1978';
423 $obj->{state_2442} = 'gl-jis-1983';
424 $obj->{state} = 'state_2842';
425 require Encode::GLJIS1978;
426 require Encode::GLJIS1983;
427 if (Encode::find_encoding ($obj->{state_2440}) and
428 Encode::find_encoding ($obj->{state_2442})) {
429 return bless $obj, 'Whatpm::Charset::DecodeHandle::ISO2022JP';
430 }
431 } elsif (defined $csdef->{perl_name}->[0]) {
432 if ($csdef->{uri}->{$XML_CHARSET.'euc-jp'} or
433 $csdef->{uri}->{$IANA_CHARSET.'euc-jp'}) {
434 $obj->{perl_encoding_name} = $csdef->{perl_name}->[0];
435 require Encode::EUCJP1997;
436 if (Encode::find_encoding ($obj->{perl_encoding_name})) {
437 return bless $obj, 'Whatpm::Charset::DecodeHandle::EUCJP';
438 }
439 } elsif ($csdef->{uri}->{$XML_CHARSET.'shift_jis'} or
440 $csdef->{uri}->{$IANA_CHARSET.'shift_jis'}) {
441 $obj->{perl_encoding_name} = $csdef->{perl_name}->[0];
442 require Encode::ShiftJIS1997;
443 if (Encode::find_encoding ($obj->{perl_encoding_name})) {
444 return bless $obj, 'Whatpm::Charset::DecodeHandle::ShiftJIS';
445 }
446 } elsif ($csdef->{is_block_safe}) {
447 $obj->{perl_encoding_name} = $csdef->{perl_name}->[0];
448 require Encode;
449 if (Encode::find_encoding ($obj->{perl_encoding_name})) {
450 return bless $obj, 'Whatpm::Charset::DecodeHandle::Encode';
451 }
452 }
453 }
454
455 $obj->{onerror}->(undef, 'charset-not-supported-error',
456 charset_uri => $obj->{charset});
457 return undef;
458 } # create_decode_handle
459
460 sub name_to_uri ($$$) {
461 my $domain = $_[1];
462 my $name = lc $_[2];
463
464 if ($domain eq 'ietf') {
465 return $IANA_CHARSET . $name;
466 } elsif ($domain eq 'xml') {
467 if ({
468 'utf-8' => 1,
469 'utf-16' => 1,
470 'iso-10646-ucs-2' => 1,
471 'iso-10646-ucs-4' => 1,
472 'iso-8859-1' => 1,
473 'iso-8859-2' => 1,
474 'iso-8859-3' => 1,
475 'iso-8859-4' => 1,
476 'iso-8859-5' => 1,
477 'iso-8859-6' => 1,
478 'iso-8859-7' => 1,
479 'iso-8859-8' => 1,
480 'iso-8859-9' => 1,
481 'iso-8859-10' => 1,
482 'iso-8859-11' => 1,
483 'iso-8859-13' => 1,
484 'iso-8859-14' => 1,
485 'iso-8859-15' => 1,
486 'iso-8859-16' => 1,
487 'iso-2022-jp' => 1,
488 'shift_jis' => 1,
489 'euc-jp' => 1,
490 }->{$name}) {
491 return $XML_CHARSET . $name;
492 }
493
494 my $uri = $IANA_CHARSET . $name;
495 return $uri if $Whatpm::Charset::CharsetDef->{$uri};
496
497 return $XML_CHARSET . $name;
498 } else {
499 return undef;
500 }
501 } # name_to_uri
502
503 sub uri_to_name ($$$) {
504 my (undef, $domain, $uri) = @_;
505
506 if ($domain eq 'xml') {
507 my $v = $Whatpm::Charset::CharsetDef->{$uri}->{xml_name};
508 return $v if defined $v;
509
510 if (substr ($uri, 0, length $XML_CHARSET) eq $XML_CHARSET) {
511 return substr ($uri, length $XML_CHARSET);
512 }
513
514 $domain = 'ietf'; ## TODO: XML encoding name has smaller range
515 }
516
517 if ($domain eq 'ietf') {
518 my $v = $Whatpm::Charset::CharsetDef->{$uri}->{iana_name};
519 return $v->[0] if defined $v;
520
521 if (substr ($uri, 0, length $IANA_CHARSET) eq $IANA_CHARSET) {
522 return substr ($uri, length $IANA_CHARSET);
523 }
524 }
525
526 return undef;
527 } # uri_to_name
528
529 require IO::Handle;
530
531 package Whatpm::Charset::DecodeHandle::ByteBuffer;
532
533 sub new ($$) {
534 my $self = bless {
535 buffer => '',
536 }, shift;
537 $self->{filehandle} = shift;
538 return $self;
539 } # new
540
541 sub read {
542 my $self = shift;
543 my $pos = length $self->{buffer};
544 my $r = $self->{filehandle}->read ($self->{buffer}, $_[1], $pos);
545 substr ($_[0], $_[2]) = substr ($self->{buffer}, $pos);
546 return $r;
547 } # read
548
549 sub close { $_[0]->{filehandle}->close }
550
551 package Whatpm::Charset::DecodeHandle::Encode;
552
553 sub charset ($) { $_[0]->{charset} }
554
555 sub close ($) { $_[0]->{filehandle}->close }
556
557 sub getc ($) {
558 my $self = $_[0];
559 return shift @{$self->{character_queue}} if @{$self->{character_queue}};
560
561 my $error;
562 if ($self->{continue}) {
563 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
564 length $self->{byte_buffer})) {
565 #
566 } else {
567 $error = 1;
568 }
569 $self->{continue} = 0;
570 } elsif (512 > length $self->{byte_buffer}) {
571 $self->{filehandle}->read ($self->{byte_buffer}, 256,
572 length $self->{byte_buffer});
573 }
574
575 my $r;
576 unless ($error) {
577 my $string = Encode::decode ($self->{perl_encoding_name},
578 $self->{byte_buffer},
579 Encode::FB_QUIET ());
580 if (length $string) {
581 push @{$self->{character_queue}}, split //, $string;
582 $r = shift @{$self->{character_queue}};
583 if (length $self->{byte_buffer}) {
584 $self->{continue} = 1;
585 }
586 } else {
587 if (length $self->{byte_buffer}) {
588 $error = 1;
589 } else {
590 $r = undef;
591 }
592 }
593 }
594
595 if ($error) {
596 $r = substr $self->{byte_buffer}, 0, 1, '';
597 $self->{onerror}->($self, 'illegal-octets-error', octets => \$r);
598 }
599
600 return $r;
601 } # getc
602
603 sub has_bom ($) { $_[0]->{has_bom} }
604
605 sub input_encoding ($) {
606 my $v = $_[0]->{input_encoding};
607 return $v if defined $v;
608
609 my $uri = $_[0]->{charset};
610 if (defined $uri) {
611 return Whatpm::Charset::DecodeHandle->uri_to_name (xml => $uri);
612 }
613
614 return undef;
615 } # input_encoding
616
617 sub onerror ($;$) {
618 if (@_ > 1) {
619 $_[0]->{onerror} = $_[1];
620 }
621
622 return $_[0]->{onerror};
623 } # onerror
624
625 sub ungetc ($$) {
626 unshift @{$_[0]->{character_queue}}, chr int ($_[1] or 0);
627 } # ungetc
628
629 package Whatpm::Charset::DecodeHandle::EUCJP;
630 push our @ISA, 'Whatpm::Charset::DecodeHandle::Encode';
631
632 sub getc ($) {
633 my $self = $_[0];
634 return shift @{$self->{character_queue}} if @{$self->{character_queue}};
635
636 my $error;
637 if ($self->{continue}) {
638 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
639 length $self->{byte_buffer})) {
640 #
641 } else {
642 $error = 1;
643 }
644 $self->{continue} = 0;
645 } elsif (512 > length $self->{byte_buffer}) {
646 $self->{filehandle}->read ($self->{byte_buffer}, 256,
647 length $self->{byte_buffer});
648 }
649
650 my $r;
651 unless ($error) {
652 my $string = Encode::decode ($self->{perl_encoding_name},
653 $self->{byte_buffer},
654 Encode::FB_QUIET ());
655 if (length $string) {
656 push @{$self->{character_queue}}, split //, $string;
657 $r = shift @{$self->{character_queue}};
658 if (length $self->{byte_buffer}) {
659 $self->{continue} = 1;
660 }
661 } else {
662 if (length $self->{byte_buffer}) {
663 $error = 1;
664 } else {
665 $r = undef;
666 }
667 }
668 }
669
670 if ($error) {
671 $r = substr $self->{byte_buffer}, 0, 1, '';
672 my $etype = 'illegal-octets-error';
673 if ($r =~ /^[\xA1-\xFE]/) {
674 if ($self->{byte_buffer} =~ s/^([\xA1-\xFE])//) {
675 $r .= $1;
676 $etype = 'unassigned-code-point-error';
677 }
678 } elsif ($r eq "\x8F") {
679 if ($self->{byte_buffer} =~ s/^([\xA1-\xFE][\xA1-\xFE]?)//) {
680 $r .= $1;
681 $etype = 'unassigned-code-point-error' if length $1 == 2;
682 }
683 } elsif ($r eq "\x8E") {
684 if ($self->{byte_buffer} =~ s/^([\xA1-\xFE])//) {
685 $r .= $1;
686 $etype = 'unassigned-code-point-error';
687 }
688 } elsif ($r eq "\xA0" or $r eq "\xFF") {
689 $etype = 'unassigned-code-point-error';
690 }
691 $self->{onerror}->($self, $etype, octets => \$r);
692 }
693
694 return $r;
695 } # getc
696
697 package Whatpm::Charset::DecodeHandle::ISO2022JP;
698 push our @ISA, 'Whatpm::Charset::DecodeHandle::Encode';
699
700 sub getc ($) {
701 my $self = $_[0];
702 return shift @{$self->{character_queue}} if @{$self->{character_queue}};
703
704 my $r;
705 A: {
706 my $error;
707 if ($self->{continue}) {
708 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
709 length $self->{byte_buffer})) {
710 #
711 } else {
712 $error = 1;
713 }
714 $self->{continue} = 0;
715 } elsif (512 > length $self->{byte_buffer}) {
716 $self->{filehandle}->read ($self->{byte_buffer}, 256,
717 length $self->{byte_buffer});
718 }
719
720 unless ($error) {
721 if ($self->{byte_buffer} =~ s/^\x1B(\x24[\x40\x42]|\x28[\x42\x4A])//) {
722 $self->{state} = {
723 "\x24\x40" => 'state_2440',
724 "\x24\x42" => 'state_2442',
725 "\x28\x42" => 'state_2842',
726 "\x28\x4A" => 'state_284A',
727 }->{$1};
728 redo A;
729 } elsif ($self->{state} eq 'state_2842') { # IRV
730 if ($self->{byte_buffer} =~ s/^([\x00-\x0D\x10-\x1A\x1C-\x7F]+)//) {
731 push @{$self->{character_queue}}, split //, $1;
732 $r = shift @{$self->{character_queue}};
733 } else {
734 if (length $self->{byte_buffer}) {
735 $error = 1;
736 } else {
737 $r = undef;
738 }
739 }
740 } elsif ($self->{state} eq 'state_284A') { # 0201
741 if ($self->{byte_buffer} =~ s/^([\x00-\x0D\x10-\x1A\x1C-\x7F]+)//) {
742 my $v = $1;
743 $v =~ tr/\x5C\x7E/\xA5\x{203E}/;
744 push @{$self->{character_queue}}, split //, $v;
745 $r = shift @{$self->{character_queue}};
746 } else {
747 if (length $self->{byte_buffer}) {
748 $error = 1;
749 } else {
750 $r = undef;
751 $self->{onerror}->($self, 'invalid-state-error',
752 state => $self->{state});
753 }
754 }
755 } elsif ($self->{state} eq 'state_2442') { # 1983
756 my $v = Encode::decode ($self->{state_2442},
757 $self->{byte_buffer},
758 Encode::FB_QUIET ());
759 if (length $v) {
760 push @{$self->{character_queue}}, split //, $v;
761 $r = shift @{$self->{character_queue}};
762 } else {
763 if (length $self->{byte_buffer}) {
764 $error = 1;
765 } else {
766 $r = undef;
767 $self->{onerror}->($self, 'invalid-state-error',
768 state => $self->{state});
769 }
770 }
771 } elsif ($self->{state} eq 'state_2440') { # 1978
772 my $v = Encode::decode ($self->{state_2440},
773 $self->{byte_buffer},
774 Encode::FB_QUIET ());
775 if (length $v) {
776 push @{$self->{character_queue}}, split //, $v;
777 $r = shift @{$self->{character_queue}};
778 } else {
779 if (length $self->{byte_buffer}) {
780 $error = 1;
781 } else {
782 $r = undef;
783 $self->{onerror}->($self, 'invalid-state-error',
784 state => $self->{state});
785 }
786 }
787 } else {
788 $error = 1;
789 }
790 }
791
792 if ($error) {
793 $r = substr $self->{byte_buffer}, 0, 1, '';
794 my $etype = 'illegal-octets-error';
795 if (($self->{state} eq 'state_2442' or
796 $self->{state} eq 'state_2440') and
797 $r =~ /^[\x21-\x7E]/ and
798 $self->{byte_buffer} =~ s/^([\x21-\x7E])//) {
799 $r .= $1;
800 $etype = 'unassigned-code-point-error';
801 } elsif ($r eq "\x1B" and
802 $self->{byte_buffer} =~ s/^\(H//) { # Old 0201
803 $r .= "(H";
804 $self->{state} = 'state_284A';
805 }
806 $self->{onerror}->($self, $etype, octets => \$r);
807 }
808 } # A
809
810 return $r;
811 } # getc
812
813 package Whatpm::Charset::DecodeHandle::ShiftJIS;
814 push our @ISA, 'Whatpm::Charset::DecodeHandle::Encode';
815
816 sub getc ($) {
817 my $self = $_[0];
818 return shift @{$self->{character_queue}} if @{$self->{character_queue}};
819
820 my $error;
821 if ($self->{continue}) {
822 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
823 length $self->{byte_buffer})) {
824 #
825 } else {
826 $error = 1;
827 }
828 $self->{continue} = 0;
829 } elsif (512 > length $self->{byte_buffer}) {
830 $self->{filehandle}->read ($self->{byte_buffer}, 256,
831 length $self->{byte_buffer});
832 }
833
834 my $r;
835 unless ($error) {
836 my $string = Encode::decode ($self->{perl_encoding_name},
837 $self->{byte_buffer},
838 Encode::FB_QUIET ());
839 if (length $string) {
840 push @{$self->{character_queue}}, split //, $string;
841 $r = shift @{$self->{character_queue}};
842 if (length $self->{byte_buffer}) {
843 $self->{continue} = 1;
844 }
845 } else {
846 if (length $self->{byte_buffer}) {
847 $error = 1;
848 } else {
849 $r = undef;
850 }
851 }
852 }
853
854 if ($error) {
855 $r = substr $self->{byte_buffer}, 0, 1, '';
856 my $etype = 'illegal-octets-error';
857 if ($r =~ /^[\x81-\x9F\xE0-\xEF]/) {
858 if ($self->{byte_buffer} =~ s/(.)//s) {
859 $r .= $1; # not limited to \x40-\xFC - \x7F
860 $etype = 'unassigned-code-point-error';
861 }
862 } elsif ($r =~ /^[\x80\xA0\xF0-\xFF]/) {
863 $etype = 'unassigned-code-point-error';
864 }
865 $self->{onerror}->($self, $etype, octets => \$r);
866 }
867
868 return $r;
869 } # getc
870
871 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:us-ascii'} =
872 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:us'} =
873 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso646-us'} =
874 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:cp367'} =
875 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ibm367'} =
876 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ansi_x3.4-1986'} =
877 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ansi_x3.4-1968'} =
878 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso-ir-6'} =
879 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:csascii'} =
880 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso_646.irv:1991'} =
881 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ascii'} = {ascii8 =>
882 '1',
883 is_block_safe =>
884 '1',
885 ietf_name =>
886 ['ansi_x3.4-1968',
887 'ansi_x3.4-1986',
888 'ascii',
889 'cp367',
890 'csascii',
891 'ibm367',
892 'iso-ir-6',
893 'iso646-us',
894 'iso_646.irv:1991',
895 'us',
896 'us-ascii',
897 'us-ascii'],
898 mime_name =>
899 'us-ascii',
900 perl_name =>
901 ['ascii',
902 'iso-646-us',
903 'us-ascii'],
904 utf8_encoding_scheme =>
905 '1',
906 'uri',
907 {'urn:x-suika-fam-cx:charset:ansi_x3.4-1968',
908 '1',
909 'urn:x-suika-fam-cx:charset:ansi_x3.4-1986',
910 '1',
911 'urn:x-suika-fam-cx:charset:ascii',
912 '1',
913 'urn:x-suika-fam-cx:charset:cp367',
914 '1',
915 'urn:x-suika-fam-cx:charset:csascii',
916 '1',
917 'urn:x-suika-fam-cx:charset:ibm367',
918 '1',
919 'urn:x-suika-fam-cx:charset:iso-ir-6',
920 '1',
921 'urn:x-suika-fam-cx:charset:iso646-us',
922 '1',
923 'urn:x-suika-fam-cx:charset:iso_646.irv:1991',
924 '1',
925 'urn:x-suika-fam-cx:charset:us',
926 '1',
927 'urn:x-suika-fam-cx:charset:us-ascii',
928 '1'},
929 };
930
931 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ascii-ctrl'} = {perl_name =>
932 ['ascii-ctrl'],
933 'uri',
934 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ascii-ctrl',
935 '1'}};
936 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.null'} = {perl_name =>
937 ['null'],
938 'uri',
939 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.null',
940 '1'}};
941 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-8'} = {ascii8 =>
942 '1',
943 bom_allowed =>
944 '1',
945 no_bom_variant =>
946 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8',
947 utf8_encoding_scheme =>
948 '1',
949 'uri',
950 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-8',
951 '1'},
952 xml_name => 'UTF-8',
953 };
954
955 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/UTF-8.RFC2279'} = {ascii8 =>
956 '1',
957 bom_allowed =>
958 '1',
959 no_bom_variant =>
960 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8',
961 utf8_encoding_scheme =>
962 '1',
963 'uri',
964 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/UTF-8.RFC2279',
965 '1'}};
966 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-8'} = {
967 ascii8 => 1,
968 is_block_safe =>
969 '1',
970 perl_name =>
971 ['utf-8'],
972 utf8_encoding_scheme =>
973 '1',
974 'uri',
975 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-8',
976 '1'}};
977 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-8'} = {
978 ascii8 => 1,
979 bom_allowed =>
980 '1',
981 no_bom_variant =>
982 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-8',
983 ietf_name =>
984 ['utf-8'],
985 mime_name =>
986 'utf-8',
987 utf8_encoding_scheme =>
988 '1',
989 'uri',
990 {'urn:x-suika-fam-cx:charset:utf-8',
991 '1'},
992 };
993
994 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8'} = {ascii8 =>
995 '1',
996 is_block_safe =>
997 '1',
998 perl_name =>
999 ['utf8'],
1000 utf8_encoding_scheme =>
1001 '1',
1002 'uri',
1003 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8',
1004 '1'}};
1005 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-16'} = {
1006 ascii16 => 1,
1007 bom_allowed =>
1008 '1',
1009 bom_required =>
1010 '1',
1011 no_bom_variant =>
1012 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1013 no_bom_variant16be =>
1014 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1015 no_bom_variant16le =>
1016 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1017 perl_name =>
1018 ['utf-16'],
1019 'uri',
1020 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-16',
1021 '1'},
1022 xml_name => 'UTF-16',
1023 };
1024
1025 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-16'} = {
1026 ascii16 => 1,
1027 bom_allowed =>
1028 '1',
1029 no_bom_variant =>
1030 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1031 no_bom_variant16be =>
1032 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1033 no_bom_variant16le =>
1034 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1035 ietf_name =>
1036 ['utf-16'],
1037 mime_name =>
1038 'utf-16',
1039 'uri',
1040 {'urn:x-suika-fam-cx:charset:utf-16',
1041 '1'},
1042 };
1043
1044 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-16be'} = {
1045 ascii16 => 1,
1046 ascii16be => 1,
1047 bom_allowed =>
1048 '1',
1049 no_bom_variant =>
1050 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1051 no_bom_variant16be =>
1052 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1053 ietf_name =>
1054 ['utf-16be'],
1055 mime_name =>
1056 'utf-16be',
1057 'uri',
1058 {'urn:x-suika-fam-cx:charset:utf-16be',
1059 '1'},
1060 };
1061
1062 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-16le'} = {
1063 ascii16 => 1,
1064 ascii16le => 1,
1065 bom_allowed =>
1066 '1',
1067 no_bom_variant =>
1068 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1069 no_bom_variant16le =>
1070 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1071 ietf_name =>
1072 ['utf-16le'],
1073 mime_name =>
1074 'utf-16le',
1075 'uri',
1076 {'urn:x-suika-fam-cx:charset:utf-16le',
1077 '1'},
1078 };
1079
1080 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be'} = {
1081 ascii16 => 1,
1082 ascii16be => 1,
1083 is_block_safe =>
1084 '1',
1085 perl_name =>
1086 ['utf-16be'],
1087 'uri',
1088 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1089 '1'}};
1090 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le'} = {
1091 ascii16 => 1,
1092 ascii16le => 1,
1093 is_block_safe =>
1094 '1',
1095 perl_name =>
1096 ['utf-16le'],
1097 'uri',
1098 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1099 '1'}};
1100 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-10646-ucs-2'} = $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso-10646-ucs-2'} = {
1101 ascii16 => 1,
1102 bom_allowed =>
1103 '1',
1104 no_bom_variant =>
1105 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le',
1106 no_bom_variant16be =>
1107 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2be',
1108 no_bom_variant16le =>
1109 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le',
1110 ietf_name =>
1111 ['csunicode',
1112 'iso-10646-ucs-2'],
1113 mime_name =>
1114 'iso-10646-ucs-2',
1115 'uri',
1116 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-10646-ucs-2',
1117 '1',
1118 'urn:x-suika-fam-cx:charset:iso-10646-ucs-2',
1119 '1'},
1120 xml_name => 'ISO-10646-UCS-2',
1121 };
1122
1123 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2be'} = {
1124 ascii16 => 1,
1125 ascii16be => 1,
1126 is_block_safe =>
1127 '1',
1128 perl_name =>
1129 ['ucs-2be'],
1130 'uri',
1131 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2be',
1132 '1'}};
1133 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le'} = {
1134 ascii16 => 1,
1135 ascii16le => 1,
1136 is_block_safe =>
1137 '1',
1138 perl_name =>
1139 ['ucs-2le'],
1140 'uri',
1141 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le',
1142 '1'}};
1143 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-10646-ucs-4'} = $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso-10646-ucs-4'} = {
1144 ascii32 => 1,
1145 bom_allowed =>
1146 '1',
1147 no_bom_variant =>
1148 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le',
1149 no_bom_variant32endian1234 =>
1150 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32be',
1151 no_bom_variant32endian4321 =>
1152 'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le',
1153 ietf_name =>
1154 ['csucs4',
1155 'iso-10646-ucs-4'],
1156 mime_name =>
1157 'iso-10646-ucs-4',
1158 'uri',
1159 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-10646-ucs-4',
1160 '1',
1161 'urn:x-suika-fam-cx:charset:iso-10646-ucs-4',
1162 '1'},
1163 xml_name => 'ISO-10646-UCS-4',
1164 };
1165
1166 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32be'} = {
1167 ascii32 => 1,
1168 ascii32endian1234 => 1,
1169 is_block_safe =>
1170 '1',
1171 perl_name =>
1172 ['ucs-4be',
1173 'utf-32be'],
1174 'uri',
1175 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32be',
1176 '1'}};
1177 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le'} = {
1178 ascii32 => 1,
1179 ascii32endian4321 => 1,
1180 is_block_safe =>
1181 '1',
1182 perl_name =>
1183 ['ucs-4le',
1184 'utf-32le'],
1185 'uri',
1186 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le',
1187 '1'}};
1188 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso_8859-1:1987'} = $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-1'} = {ascii8 =>
1189 '1',
1190 is_block_safe =>
1191 '1',
1192 ietf_name =>
1193 ['cp819',
1194 'csisolatin1',
1195 'ibm819',
1196 'iso-8859-1',
1197 'iso-8859-1',
1198 'iso-ir-100',
1199 'iso_8859-1',
1200 'iso_8859-1:1987',
1201 'l1',
1202 'latin1'],
1203 mime_name =>
1204 'iso-8859-1',
1205 perl_name =>
1206 ['iso-8859-1',
1207 'latin1'],
1208 'uri',
1209 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-1',
1210 '1',
1211 'urn:x-suika-fam-cx:charset:iso_8859-1:1987',
1212 '1'},
1213 xml_name => 'ISO-8859-1',
1214 };
1215
1216 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-2'} = {ascii8 =>
1217 '1',
1218 is_block_safe =>
1219 '1',
1220 'uri',
1221 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-2',
1222 '1'},
1223 xml_name => 'ISO-8859-2',
1224 };
1225
1226 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-3'} = {ascii8 =>
1227 '1',
1228 is_block_safe =>
1229 '1',
1230 'uri',
1231 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-3',
1232 '1'},
1233 xml_name => 'ISO-8859-3',
1234 };
1235
1236 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-4'} = {ascii8 =>
1237 '1',
1238 is_block_safe =>
1239 '1',
1240 'uri',
1241 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-4',
1242 '1'},
1243 xml_name => 'ISO-8859-4',
1244 };
1245
1246 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-5'} = {ascii8 =>
1247 '1',
1248 is_block_safe =>
1249 '1',
1250 'uri',
1251 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-5',
1252 '1'},
1253 xml_name => 'ISO-8859-5',
1254 };
1255
1256 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-6'} = {ascii8 =>
1257 '1',
1258 is_block_safe =>
1259 '1',
1260 'uri',
1261 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-6',
1262 '1'},
1263 xml_name => 'ISO-8859-6',
1264 };
1265
1266 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-7'} = {ascii8 =>
1267 '1',
1268 is_block_safe =>
1269 '1',
1270 'uri',
1271 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-7',
1272 '1'},
1273 xml_name => 'ISO-8859-7',
1274 };
1275
1276 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-8'} = {ascii8 =>
1277 '1',
1278 is_block_safe =>
1279 '1',
1280 'uri',
1281 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-8',
1282 '1'},
1283 xml_name => 'ISO-8859-8',
1284 };
1285
1286 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-9'} = {ascii8 =>
1287 '1',
1288 is_block_safe =>
1289 '1',
1290 'uri',
1291 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-9',
1292 '1'},
1293 xml_name => 'ISO-8859-9',
1294 };
1295
1296 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-10'} = {ascii8 =>
1297 '1',
1298 is_block_safe =>
1299 '1',
1300 'uri',
1301 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-10',
1302 '1'},
1303 xml_name => 'ISO-8859-10',
1304 };
1305
1306 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-11'} = {ascii8 =>
1307 '1',
1308 is_block_safe =>
1309 '1',
1310 'uri',
1311 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-11',
1312 '1'},
1313 xml_name => 'ISO-8859-11',
1314 };
1315
1316 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-13'} = {ascii8 =>
1317 '1',
1318 is_block_safe =>
1319 '1',
1320 'uri',
1321 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-13',
1322 '1'},
1323 xml_name => 'ISO-8859-13',
1324 };
1325
1326 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-14'} = {ascii8 =>
1327 '1',
1328 is_block_safe =>
1329 '1',
1330 'uri',
1331 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-14',
1332 '1'},
1333 xml_name => 'ISO-8859-14',
1334 };
1335
1336 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-15'} = {ascii8 =>
1337 '1',
1338 is_block_safe =>
1339 '1',
1340 'uri',
1341 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-15',
1342 '1'},
1343 xml_name => 'ISO-8859-15',
1344 };
1345
1346 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-16'} = {ascii8 =>
1347 '1',
1348 is_block_safe =>
1349 '1',
1350 'uri',
1351 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-16',
1352 '1'},
1353 xml_name => 'ISO-8859-16',
1354 };
1355
1356 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-2022-jp'} = {ascii8 =>
1357 '1',
1358 'uri',
1359 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-2022-jp',
1360 '1'},
1361 xml_name => 'ISO-2022-JP',
1362 };
1363
1364 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso-2022-jp'} = {ascii8 =>
1365 '1',
1366 ietf_name =>
1367 ['csiso2022jp',
1368 'iso-2022-jp',
1369 'iso-2022-jp'],
1370 mime_name =>
1371 'iso-2022-jp',
1372 'uri',
1373 {'urn:x-suika-fam-cx:charset:iso-2022-jp',
1374 '1'},
1375 };
1376
1377 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.iso-2022-jp'} = {ascii8 =>
1378 '1',
1379 perl_name =>
1380 ['iso-2022-jp'],
1381 'uri',
1382 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.iso-2022-jp',
1383 '1'}};
1384 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:shift_jis'} = $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.shift_jis'} = {ascii8 =>
1385 '1',
1386 is_block_safe =>
1387 '1',
1388 ietf_name =>
1389 ['csshiftjis',
1390 'ms_kanji',
1391 'shift_jis',
1392 'shift_jis'],
1393 mime_name =>
1394 'shift_jis',
1395 perl_name =>
1396 ['shift-jis-1997'],
1397 'uri',
1398 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.shift_jis',
1399 '1',
1400 'urn:x-suika-fam-cx:charset:shift_jis',
1401 '1'},
1402 xml_name => 'Shift_JIS',
1403 };
1404
1405 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.shiftjis'} = {ascii8 =>
1406 '1',
1407 is_block_safe =>
1408 '1',
1409 perl_name =>
1410 ['shiftjis',
1411 'sjis'],
1412 'uri',
1413 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.shiftjis',
1414 '1'}};
1415 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:euc-jp'} = $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.euc-jp'} = $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:extended_unix_code_packed_format_for_japanese'} = {ascii8 =>
1416 '1',
1417 is_block_safe =>
1418 '1',
1419 ietf_name =>
1420 ['cseucpkdfmtjapanese',
1421 'euc-jp',
1422 'euc-jp',
1423 'extended_unix_code_packed_format_for_japanese'],
1424 mime_name =>
1425 'euc-jp',
1426 perl_name =>
1427 ['euc-jp-1997'],
1428 'uri',
1429 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.euc-jp',
1430 '1',
1431 'urn:x-suika-fam-cx:charset:euc-jp',
1432 '1',
1433 'urn:x-suika-fam-cx:charset:extended_unix_code_packed_format_for_japanese',
1434 '1'},
1435 xml_name => 'EUC-JP',
1436 };
1437
1438 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.euc-jp'} = {ascii8 =>
1439 '1',
1440 is_block_safe =>
1441 '1',
1442 perl_name =>
1443 ['euc-jp',
1444 'ujis'],
1445 'uri',
1446 {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.euc-jp',
1447 '1'}};
1448
1449 1;
1450 ## $Date: 2007/07/15 16:51:14 $

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24