/[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.7 - (hide annotations) (download)
Wed Sep 10 10:27:09 2008 UTC (16 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +26 -11 lines
++ whatpm/Whatpm/ChangeLog	10 Sep 2008 10:25:19 -0000
2008-09-10  Wakaba  <wakaba@suika.fam.cx>

	* ContentChecker.pm: Support for charset-layer error levels.

	* HTML.pm.src: Don't specify |text| argument for the
	|chardecode:fallback| error, since it is not the encoding
	being used alternatively.

++ whatpm/Whatpm/Charset/ChangeLog	10 Sep 2008 10:26:52 -0000
2008-09-10  Wakaba  <wakaba@suika.fam.cx>

	* DecodeHandle.pm: Set error levels.

	* WebLatin1.pm: Support for |us-ascii| and |iso-8859-5|
	charsets (this module no longer for Latin1, but for Latin*
	encodings).

	* WebThai.pm: Support for |tis-620| charset.

1 wakaba 1.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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
24 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = $1;
32 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
42 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
52 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
63 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
72 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
86 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
99 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
110 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
120 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
131 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
140 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
154 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
167 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-16';
179 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
190 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-16';
204 wakaba 1.1 $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 wakaba 1.2 $obj->{input_encoding} = 'UTF-16';
212 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = $1;
223 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-16';
235 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
246 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-16';
260 wakaba 1.1 $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 wakaba 1.2 $obj->{input_encoding} = 'UTF-16';
268 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = $1;
277 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
291 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
300 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
314 wakaba 1.1 }
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 wakaba 1.2 $obj->{input_encoding} = $1;
325 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
339 wakaba 1.1 $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 wakaba 1.2 $obj->{input_encoding} = $1;
352 wakaba 1.1 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 wakaba 1.2 $obj->{input_encoding} = 'UTF-8';
366 wakaba 1.1 $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 wakaba 1.2
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 wakaba 1.1 return substr ($uri, length $IANA_CHARSET);
523     }
524     }
525    
526     return undef;
527     } # uri_to_name
528    
529 wakaba 1.3 require IO::Handle;
530    
531     package Whatpm::Charset::DecodeHandle::ByteBuffer;
532    
533 wakaba 1.7 ## NOTE: Provides a byte buffer wrapper object.
534    
535 wakaba 1.3 sub new ($$) {
536     my $self = bless {
537     buffer => '',
538     }, shift;
539     $self->{filehandle} = shift;
540     return $self;
541     } # new
542    
543     sub read {
544     my $self = shift;
545     my $pos = length $self->{buffer};
546     my $r = $self->{filehandle}->read ($self->{buffer}, $_[1], $pos);
547     substr ($_[0], $_[2]) = substr ($self->{buffer}, $pos);
548     return $r;
549     } # read
550    
551     sub close { $_[0]->{filehandle}->close }
552    
553 wakaba 1.1 package Whatpm::Charset::DecodeHandle::Encode;
554    
555 wakaba 1.7 ## NOTE: Provides a Perl |Encode| module wrapper object.
556    
557 wakaba 1.1 sub charset ($) { $_[0]->{charset} }
558    
559 wakaba 1.3 sub close ($) { $_[0]->{filehandle}->close }
560 wakaba 1.1
561     sub getc ($) {
562     my $self = $_[0];
563     return shift @{$self->{character_queue}} if @{$self->{character_queue}};
564    
565     my $error;
566     if ($self->{continue}) {
567 wakaba 1.3 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
568     length $self->{byte_buffer})) {
569 wakaba 1.1 #
570     } else {
571     $error = 1;
572     }
573     $self->{continue} = 0;
574     } elsif (512 > length $self->{byte_buffer}) {
575 wakaba 1.3 $self->{filehandle}->read ($self->{byte_buffer}, 256,
576     length $self->{byte_buffer});
577 wakaba 1.1 }
578    
579     my $r;
580     unless ($error) {
581 wakaba 1.4 if (not $self->{bom_checked}) {
582     if (defined $self->{bom_pattern}) {
583     if ($self->{byte_buffer} =~ s/^$self->{bom_pattern}//) {
584     $self->{has_bom} = 1;
585     }
586     }
587     $self->{bom_checked} = 1;
588     }
589    
590 wakaba 1.1 my $string = Encode::decode ($self->{perl_encoding_name},
591     $self->{byte_buffer},
592     Encode::FB_QUIET ());
593     if (length $string) {
594     push @{$self->{character_queue}}, split //, $string;
595     $r = shift @{$self->{character_queue}};
596     if (length $self->{byte_buffer}) {
597     $self->{continue} = 1;
598     }
599     } else {
600     if (length $self->{byte_buffer}) {
601     $error = 1;
602     } else {
603     $r = undef;
604     }
605     }
606     }
607    
608     if ($error) {
609     $r = substr $self->{byte_buffer}, 0, 1, '';
610 wakaba 1.6 my $fallback = $self->{fallback}->{$r};
611     if (defined $fallback) {
612 wakaba 1.7 ## NOTE: This is an HTML5 parse error.
613 wakaba 1.6 $self->{onerror}->($self, 'fallback-char-error', octets => \$r,
614     char => \$fallback,
615 wakaba 1.7 level => $self->{level}->{$self->{error_level}->{'fallback-char-error'}});
616 wakaba 1.6 return $fallback;
617 wakaba 1.7 } elsif (exists $self->{fallback}->{$r}) {
618     ## NOTE: This is an HTML5 parse error. In addition, the octet
619     ## is not assigned with a character.
620     $self->{onerror}->($self, 'fallback-unassigned-error', octets => \$r,
621     level => $self->{level}->{$self->{error_level}->{'fallback-unassigned-error'}});
622 wakaba 1.6 } else {
623 wakaba 1.7 $self->{onerror}->($self, 'illegal-octets-error', octets => \$r,
624     level => $self->{level}->{$self->{error_level}->{'illegal-octets-error'}});
625 wakaba 1.6 }
626 wakaba 1.1 }
627    
628     return $r;
629     } # getc
630    
631     sub has_bom ($) { $_[0]->{has_bom} }
632    
633 wakaba 1.2 sub input_encoding ($) {
634     my $v = $_[0]->{input_encoding};
635     return $v if defined $v;
636    
637     my $uri = $_[0]->{charset};
638     if (defined $uri) {
639     return Whatpm::Charset::DecodeHandle->uri_to_name (xml => $uri);
640     }
641    
642     return undef;
643     } # input_encoding
644 wakaba 1.1
645     sub onerror ($;$) {
646     if (@_ > 1) {
647     $_[0]->{onerror} = $_[1];
648     }
649    
650     return $_[0]->{onerror};
651     } # onerror
652    
653     sub ungetc ($$) {
654     unshift @{$_[0]->{character_queue}}, chr int ($_[1] or 0);
655     } # ungetc
656    
657     package Whatpm::Charset::DecodeHandle::EUCJP;
658     push our @ISA, 'Whatpm::Charset::DecodeHandle::Encode';
659    
660     sub getc ($) {
661     my $self = $_[0];
662     return shift @{$self->{character_queue}} if @{$self->{character_queue}};
663    
664     my $error;
665     if ($self->{continue}) {
666 wakaba 1.3 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
667     length $self->{byte_buffer})) {
668 wakaba 1.1 #
669     } else {
670     $error = 1;
671     }
672     $self->{continue} = 0;
673     } elsif (512 > length $self->{byte_buffer}) {
674 wakaba 1.3 $self->{filehandle}->read ($self->{byte_buffer}, 256,
675     length $self->{byte_buffer});
676 wakaba 1.1 }
677    
678     my $r;
679     unless ($error) {
680     my $string = Encode::decode ($self->{perl_encoding_name},
681     $self->{byte_buffer},
682     Encode::FB_QUIET ());
683     if (length $string) {
684     push @{$self->{character_queue}}, split //, $string;
685     $r = shift @{$self->{character_queue}};
686     if (length $self->{byte_buffer}) {
687     $self->{continue} = 1;
688     }
689     } else {
690     if (length $self->{byte_buffer}) {
691     $error = 1;
692     } else {
693     $r = undef;
694     }
695     }
696     }
697    
698     if ($error) {
699     $r = substr $self->{byte_buffer}, 0, 1, '';
700     my $etype = 'illegal-octets-error';
701     if ($r =~ /^[\xA1-\xFE]/) {
702     if ($self->{byte_buffer} =~ s/^([\xA1-\xFE])//) {
703     $r .= $1;
704     $etype = 'unassigned-code-point-error';
705     }
706     } elsif ($r eq "\x8F") {
707     if ($self->{byte_buffer} =~ s/^([\xA1-\xFE][\xA1-\xFE]?)//) {
708     $r .= $1;
709     $etype = 'unassigned-code-point-error' if length $1 == 2;
710     }
711     } elsif ($r eq "\x8E") {
712     if ($self->{byte_buffer} =~ s/^([\xA1-\xFE])//) {
713     $r .= $1;
714     $etype = 'unassigned-code-point-error';
715     }
716     } elsif ($r eq "\xA0" or $r eq "\xFF") {
717     $etype = 'unassigned-code-point-error';
718     }
719 wakaba 1.7 $self->{onerror}->($self, $etype, octets => \$r,
720     level => $self->{level}->{$self->{error_level}->{$etype}});
721 wakaba 1.1 }
722    
723     return $r;
724     } # getc
725    
726     package Whatpm::Charset::DecodeHandle::ISO2022JP;
727     push our @ISA, 'Whatpm::Charset::DecodeHandle::Encode';
728    
729     sub getc ($) {
730     my $self = $_[0];
731     return shift @{$self->{character_queue}} if @{$self->{character_queue}};
732    
733     my $r;
734     A: {
735     my $error;
736     if ($self->{continue}) {
737 wakaba 1.3 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
738     length $self->{byte_buffer})) {
739 wakaba 1.1 #
740     } else {
741     $error = 1;
742     }
743     $self->{continue} = 0;
744     } elsif (512 > length $self->{byte_buffer}) {
745 wakaba 1.3 $self->{filehandle}->read ($self->{byte_buffer}, 256,
746     length $self->{byte_buffer});
747 wakaba 1.1 }
748    
749     unless ($error) {
750     if ($self->{byte_buffer} =~ s/^\x1B(\x24[\x40\x42]|\x28[\x42\x4A])//) {
751     $self->{state} = {
752     "\x24\x40" => 'state_2440',
753     "\x24\x42" => 'state_2442',
754     "\x28\x42" => 'state_2842',
755     "\x28\x4A" => 'state_284A',
756     }->{$1};
757     redo A;
758     } elsif ($self->{state} eq 'state_2842') { # IRV
759     if ($self->{byte_buffer} =~ s/^([\x00-\x0D\x10-\x1A\x1C-\x7F]+)//) {
760     push @{$self->{character_queue}}, split //, $1;
761     $r = shift @{$self->{character_queue}};
762     } else {
763     if (length $self->{byte_buffer}) {
764     $error = 1;
765     } else {
766     $r = undef;
767     }
768     }
769     } elsif ($self->{state} eq 'state_284A') { # 0201
770     if ($self->{byte_buffer} =~ s/^([\x00-\x0D\x10-\x1A\x1C-\x7F]+)//) {
771     my $v = $1;
772     $v =~ tr/\x5C\x7E/\xA5\x{203E}/;
773     push @{$self->{character_queue}}, split //, $v;
774     $r = shift @{$self->{character_queue}};
775     } else {
776     if (length $self->{byte_buffer}) {
777     $error = 1;
778     } else {
779     $r = undef;
780     $self->{onerror}->($self, 'invalid-state-error',
781 wakaba 1.7 state => $self->{state},
782     level => $self->{level}->{$self->{error_level}->{'invalid-state-error'}});
783 wakaba 1.1 }
784     }
785     } elsif ($self->{state} eq 'state_2442') { # 1983
786     my $v = Encode::decode ($self->{state_2442},
787     $self->{byte_buffer},
788     Encode::FB_QUIET ());
789     if (length $v) {
790     push @{$self->{character_queue}}, split //, $v;
791     $r = shift @{$self->{character_queue}};
792     } else {
793     if (length $self->{byte_buffer}) {
794     $error = 1;
795     } else {
796     $r = undef;
797     $self->{onerror}->($self, 'invalid-state-error',
798 wakaba 1.7 state => $self->{state},
799     level => $self->{level}->{$self->{error_level}->{'invalid-state-error'}});
800 wakaba 1.1 }
801     }
802     } elsif ($self->{state} eq 'state_2440') { # 1978
803     my $v = Encode::decode ($self->{state_2440},
804     $self->{byte_buffer},
805     Encode::FB_QUIET ());
806     if (length $v) {
807     push @{$self->{character_queue}}, split //, $v;
808     $r = shift @{$self->{character_queue}};
809     } else {
810     if (length $self->{byte_buffer}) {
811     $error = 1;
812     } else {
813     $r = undef;
814     $self->{onerror}->($self, 'invalid-state-error',
815 wakaba 1.7 state => $self->{state},
816     level => $self->{level}->{$self->{error_level}->{'invalid-state-error'}});
817 wakaba 1.1 }
818     }
819     } else {
820     $error = 1;
821     }
822     }
823    
824     if ($error) {
825     $r = substr $self->{byte_buffer}, 0, 1, '';
826     my $etype = 'illegal-octets-error';
827     if (($self->{state} eq 'state_2442' or
828     $self->{state} eq 'state_2440') and
829     $r =~ /^[\x21-\x7E]/ and
830     $self->{byte_buffer} =~ s/^([\x21-\x7E])//) {
831     $r .= $1;
832     $etype = 'unassigned-code-point-error';
833     } elsif ($r eq "\x1B" and
834     $self->{byte_buffer} =~ s/^\(H//) { # Old 0201
835     $r .= "(H";
836     $self->{state} = 'state_284A';
837     }
838 wakaba 1.7 $self->{onerror}->($self, $etype, octets => \$r,
839     level => $self->{level}->{$self->{error_level}->{$etype}});
840 wakaba 1.1 }
841     } # A
842    
843     return $r;
844     } # getc
845    
846     package Whatpm::Charset::DecodeHandle::ShiftJIS;
847     push our @ISA, 'Whatpm::Charset::DecodeHandle::Encode';
848    
849     sub getc ($) {
850     my $self = $_[0];
851     return shift @{$self->{character_queue}} if @{$self->{character_queue}};
852    
853     my $error;
854     if ($self->{continue}) {
855 wakaba 1.3 if ($self->{filehandle}->read ($self->{byte_buffer}, 256,
856     length $self->{byte_buffer})) {
857 wakaba 1.1 #
858     } else {
859     $error = 1;
860     }
861     $self->{continue} = 0;
862     } elsif (512 > length $self->{byte_buffer}) {
863 wakaba 1.3 $self->{filehandle}->read ($self->{byte_buffer}, 256,
864     length $self->{byte_buffer});
865 wakaba 1.1 }
866    
867     my $r;
868     unless ($error) {
869     my $string = Encode::decode ($self->{perl_encoding_name},
870     $self->{byte_buffer},
871     Encode::FB_QUIET ());
872     if (length $string) {
873     push @{$self->{character_queue}}, split //, $string;
874     $r = shift @{$self->{character_queue}};
875     if (length $self->{byte_buffer}) {
876     $self->{continue} = 1;
877     }
878     } else {
879     if (length $self->{byte_buffer}) {
880     $error = 1;
881     } else {
882     $r = undef;
883     }
884     }
885     }
886    
887     if ($error) {
888     $r = substr $self->{byte_buffer}, 0, 1, '';
889     my $etype = 'illegal-octets-error';
890 wakaba 1.5 if ($r =~ /^[\x81-\x9F\xE0-\xFC]/) {
891 wakaba 1.1 if ($self->{byte_buffer} =~ s/(.)//s) {
892     $r .= $1; # not limited to \x40-\xFC - \x7F
893     $etype = 'unassigned-code-point-error';
894     }
895 wakaba 1.5 ## NOTE: Range [\xF0-\xFC] is unassigned and may be used as a single-byte
896     ## character or as the first-byte of a double-byte character according
897     ## to JIS X 0208:1997 Appendix 1. However, the current practice is
898     ## use the range as the first-byte of double-byte characters.
899     } elsif ($r =~ /^[\x80\xA0\xFD-\xFF]/) {
900 wakaba 1.1 $etype = 'unassigned-code-point-error';
901     }
902 wakaba 1.7 $self->{onerror}->($self, $etype, octets => \$r,
903     level => $self->{level}->{$self->{error_level}->{$etype}});
904 wakaba 1.1 }
905    
906     return $r;
907     } # getc
908    
909     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:us-ascii'} =
910     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:us'} =
911     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso646-us'} =
912     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:cp367'} =
913     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ibm367'} =
914     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ansi_x3.4-1986'} =
915     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ansi_x3.4-1968'} =
916     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso-ir-6'} =
917     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:csascii'} =
918     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso_646.irv:1991'} =
919     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:ascii'} = {ascii8 =>
920     '1',
921     is_block_safe =>
922     '1',
923     ietf_name =>
924     ['ansi_x3.4-1968',
925     'ansi_x3.4-1986',
926     'ascii',
927     'cp367',
928     'csascii',
929     'ibm367',
930     'iso-ir-6',
931     'iso646-us',
932     'iso_646.irv:1991',
933     'us',
934     'us-ascii',
935     'us-ascii'],
936     mime_name =>
937     'us-ascii',
938     perl_name =>
939     ['ascii',
940     'iso-646-us',
941     'us-ascii'],
942     utf8_encoding_scheme =>
943     '1',
944     'uri',
945     {'urn:x-suika-fam-cx:charset:ansi_x3.4-1968',
946     '1',
947     'urn:x-suika-fam-cx:charset:ansi_x3.4-1986',
948     '1',
949     'urn:x-suika-fam-cx:charset:ascii',
950     '1',
951     'urn:x-suika-fam-cx:charset:cp367',
952     '1',
953     'urn:x-suika-fam-cx:charset:csascii',
954     '1',
955     'urn:x-suika-fam-cx:charset:ibm367',
956     '1',
957     'urn:x-suika-fam-cx:charset:iso-ir-6',
958     '1',
959     'urn:x-suika-fam-cx:charset:iso646-us',
960     '1',
961     'urn:x-suika-fam-cx:charset:iso_646.irv:1991',
962     '1',
963     'urn:x-suika-fam-cx:charset:us',
964     '1',
965     'urn:x-suika-fam-cx:charset:us-ascii',
966     '1'},
967 wakaba 1.2 };
968    
969 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ascii-ctrl'} = {perl_name =>
970     ['ascii-ctrl'],
971     'uri',
972     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ascii-ctrl',
973     '1'}};
974     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.null'} = {perl_name =>
975     ['null'],
976     'uri',
977     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.null',
978     '1'}};
979     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-8'} = {ascii8 =>
980     '1',
981     bom_allowed =>
982     '1',
983     no_bom_variant =>
984     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8',
985     utf8_encoding_scheme =>
986     '1',
987     'uri',
988     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-8',
989     '1'},
990 wakaba 1.2 xml_name => 'UTF-8',
991     };
992    
993 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/UTF-8.RFC2279'} = {ascii8 =>
994     '1',
995     bom_allowed =>
996     '1',
997     no_bom_variant =>
998     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8',
999     utf8_encoding_scheme =>
1000     '1',
1001     'uri',
1002     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/UTF-8.RFC2279',
1003     '1'}};
1004     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-8'} = {
1005     ascii8 => 1,
1006     is_block_safe =>
1007     '1',
1008     perl_name =>
1009     ['utf-8'],
1010     utf8_encoding_scheme =>
1011     '1',
1012     'uri',
1013     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-8',
1014     '1'}};
1015     $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-8'} = {
1016     ascii8 => 1,
1017     bom_allowed =>
1018     '1',
1019     no_bom_variant =>
1020     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-8',
1021     ietf_name =>
1022     ['utf-8'],
1023     mime_name =>
1024     'utf-8',
1025     utf8_encoding_scheme =>
1026     '1',
1027     'uri',
1028     {'urn:x-suika-fam-cx:charset:utf-8',
1029     '1'},
1030 wakaba 1.2 };
1031    
1032 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8'} = {ascii8 =>
1033     '1',
1034     is_block_safe =>
1035     '1',
1036     perl_name =>
1037     ['utf8'],
1038     utf8_encoding_scheme =>
1039     '1',
1040     'uri',
1041     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf8',
1042     '1'}};
1043     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-16'} = {
1044     ascii16 => 1,
1045     bom_allowed =>
1046     '1',
1047     bom_required =>
1048     '1',
1049     no_bom_variant =>
1050     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1051     no_bom_variant16be =>
1052     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1053     no_bom_variant16le =>
1054     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1055     perl_name =>
1056     ['utf-16'],
1057     'uri',
1058     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.utf-16',
1059     '1'},
1060 wakaba 1.2 xml_name => 'UTF-16',
1061     };
1062    
1063 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-16'} = {
1064     ascii16 => 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_variant16be =>
1070     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1071     no_bom_variant16le =>
1072     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1073     ietf_name =>
1074     ['utf-16'],
1075     mime_name =>
1076     'utf-16',
1077     'uri',
1078     {'urn:x-suika-fam-cx:charset:utf-16',
1079     '1'},
1080 wakaba 1.2 };
1081    
1082 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-16be'} = {
1083     ascii16 => 1,
1084     ascii16be => 1,
1085     bom_allowed =>
1086     '1',
1087     no_bom_variant =>
1088     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1089     no_bom_variant16be =>
1090     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1091     ietf_name =>
1092     ['utf-16be'],
1093     mime_name =>
1094     'utf-16be',
1095     'uri',
1096     {'urn:x-suika-fam-cx:charset:utf-16be',
1097     '1'},
1098 wakaba 1.2 };
1099    
1100 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:utf-16le'} = {
1101     ascii16 => 1,
1102     ascii16le => 1,
1103     bom_allowed =>
1104     '1',
1105     no_bom_variant =>
1106     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1107     no_bom_variant16le =>
1108     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1109     ietf_name =>
1110     ['utf-16le'],
1111     mime_name =>
1112     'utf-16le',
1113     'uri',
1114     {'urn:x-suika-fam-cx:charset:utf-16le',
1115     '1'},
1116 wakaba 1.2 };
1117    
1118 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be'} = {
1119     ascii16 => 1,
1120     ascii16be => 1,
1121     is_block_safe =>
1122     '1',
1123     perl_name =>
1124     ['utf-16be'],
1125     'uri',
1126     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16be',
1127     '1'}};
1128     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le'} = {
1129     ascii16 => 1,
1130     ascii16le => 1,
1131     is_block_safe =>
1132     '1',
1133     perl_name =>
1134     ['utf-16le'],
1135     'uri',
1136     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-16le',
1137     '1'}};
1138     $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'} = {
1139     ascii16 => 1,
1140     bom_allowed =>
1141     '1',
1142     no_bom_variant =>
1143     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le',
1144     no_bom_variant16be =>
1145     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2be',
1146     no_bom_variant16le =>
1147     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le',
1148     ietf_name =>
1149     ['csunicode',
1150     'iso-10646-ucs-2'],
1151     mime_name =>
1152     'iso-10646-ucs-2',
1153     'uri',
1154     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-10646-ucs-2',
1155     '1',
1156     'urn:x-suika-fam-cx:charset:iso-10646-ucs-2',
1157     '1'},
1158 wakaba 1.2 xml_name => 'ISO-10646-UCS-2',
1159     };
1160    
1161 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2be'} = {
1162     ascii16 => 1,
1163     ascii16be => 1,
1164     is_block_safe =>
1165     '1',
1166     perl_name =>
1167     ['ucs-2be'],
1168     'uri',
1169     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2be',
1170     '1'}};
1171     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le'} = {
1172     ascii16 => 1,
1173     ascii16le => 1,
1174     is_block_safe =>
1175     '1',
1176     perl_name =>
1177     ['ucs-2le'],
1178     'uri',
1179     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.ucs-2le',
1180     '1'}};
1181     $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'} = {
1182     ascii32 => 1,
1183     bom_allowed =>
1184     '1',
1185     no_bom_variant =>
1186     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le',
1187     no_bom_variant32endian1234 =>
1188     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32be',
1189     no_bom_variant32endian4321 =>
1190     'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le',
1191     ietf_name =>
1192     ['csucs4',
1193     'iso-10646-ucs-4'],
1194     mime_name =>
1195     'iso-10646-ucs-4',
1196     'uri',
1197     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-10646-ucs-4',
1198     '1',
1199     'urn:x-suika-fam-cx:charset:iso-10646-ucs-4',
1200     '1'},
1201 wakaba 1.2 xml_name => 'ISO-10646-UCS-4',
1202     };
1203    
1204 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32be'} = {
1205     ascii32 => 1,
1206     ascii32endian1234 => 1,
1207     is_block_safe =>
1208     '1',
1209     perl_name =>
1210     ['ucs-4be',
1211     'utf-32be'],
1212     'uri',
1213     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32be',
1214     '1'}};
1215     $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le'} = {
1216     ascii32 => 1,
1217     ascii32endian4321 => 1,
1218     is_block_safe =>
1219     '1',
1220     perl_name =>
1221     ['ucs-4le',
1222     'utf-32le'],
1223     'uri',
1224     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.utf-32le',
1225     '1'}};
1226     $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 =>
1227     '1',
1228     is_block_safe =>
1229     '1',
1230     ietf_name =>
1231     ['cp819',
1232     'csisolatin1',
1233     'ibm819',
1234     'iso-8859-1',
1235     'iso-8859-1',
1236     'iso-ir-100',
1237     'iso_8859-1',
1238     'iso_8859-1:1987',
1239     'l1',
1240     'latin1'],
1241     mime_name =>
1242     'iso-8859-1',
1243     perl_name =>
1244     ['iso-8859-1',
1245     'latin1'],
1246     'uri',
1247     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-1',
1248     '1',
1249     'urn:x-suika-fam-cx:charset:iso_8859-1:1987',
1250     '1'},
1251 wakaba 1.2 xml_name => 'ISO-8859-1',
1252     };
1253    
1254 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-2'} = {ascii8 =>
1255     '1',
1256     is_block_safe =>
1257     '1',
1258     'uri',
1259     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-2',
1260     '1'},
1261 wakaba 1.2 xml_name => 'ISO-8859-2',
1262     };
1263    
1264 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-3'} = {ascii8 =>
1265     '1',
1266     is_block_safe =>
1267     '1',
1268     'uri',
1269     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-3',
1270     '1'},
1271 wakaba 1.2 xml_name => 'ISO-8859-3',
1272     };
1273    
1274 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-4'} = {ascii8 =>
1275     '1',
1276     is_block_safe =>
1277     '1',
1278     'uri',
1279     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-4',
1280     '1'},
1281 wakaba 1.2 xml_name => 'ISO-8859-4',
1282     };
1283    
1284 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-5'} = {ascii8 =>
1285     '1',
1286     is_block_safe =>
1287     '1',
1288     'uri',
1289     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-5',
1290     '1'},
1291 wakaba 1.2 xml_name => 'ISO-8859-5',
1292     };
1293    
1294 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-6'} = {ascii8 =>
1295     '1',
1296     is_block_safe =>
1297     '1',
1298     'uri',
1299     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-6',
1300     '1'},
1301 wakaba 1.2 xml_name => 'ISO-8859-6',
1302     };
1303    
1304 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-7'} = {ascii8 =>
1305     '1',
1306     is_block_safe =>
1307     '1',
1308     'uri',
1309     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-7',
1310     '1'},
1311 wakaba 1.2 xml_name => 'ISO-8859-7',
1312     };
1313    
1314 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-8'} = {ascii8 =>
1315     '1',
1316     is_block_safe =>
1317     '1',
1318     'uri',
1319     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-8',
1320     '1'},
1321 wakaba 1.2 xml_name => 'ISO-8859-8',
1322     };
1323    
1324 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-9'} = {ascii8 =>
1325     '1',
1326     is_block_safe =>
1327     '1',
1328     'uri',
1329     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-9',
1330     '1'},
1331 wakaba 1.2 xml_name => 'ISO-8859-9',
1332     };
1333    
1334 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-10'} = {ascii8 =>
1335     '1',
1336     is_block_safe =>
1337     '1',
1338     'uri',
1339     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-10',
1340     '1'},
1341 wakaba 1.2 xml_name => 'ISO-8859-10',
1342     };
1343    
1344 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-11'} = {ascii8 =>
1345     '1',
1346     is_block_safe =>
1347     '1',
1348     'uri',
1349     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-11',
1350     '1'},
1351 wakaba 1.2 xml_name => 'ISO-8859-11',
1352     };
1353    
1354 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-13'} = {ascii8 =>
1355     '1',
1356     is_block_safe =>
1357     '1',
1358     'uri',
1359     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-13',
1360     '1'},
1361 wakaba 1.2 xml_name => 'ISO-8859-13',
1362     };
1363    
1364 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-14'} = {ascii8 =>
1365     '1',
1366     is_block_safe =>
1367     '1',
1368     'uri',
1369     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-14',
1370     '1'},
1371 wakaba 1.2 xml_name => 'ISO-8859-14',
1372     };
1373    
1374 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-15'} = {ascii8 =>
1375     '1',
1376     is_block_safe =>
1377     '1',
1378     'uri',
1379     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-15',
1380     '1'},
1381 wakaba 1.2 xml_name => 'ISO-8859-15',
1382     };
1383    
1384 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-16'} = {ascii8 =>
1385     '1',
1386     is_block_safe =>
1387     '1',
1388     'uri',
1389     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-8859-16',
1390     '1'},
1391 wakaba 1.2 xml_name => 'ISO-8859-16',
1392     };
1393    
1394 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-2022-jp'} = {ascii8 =>
1395     '1',
1396     'uri',
1397     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.iso-2022-jp',
1398     '1'},
1399 wakaba 1.2 xml_name => 'ISO-2022-JP',
1400     };
1401    
1402 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'urn:x-suika-fam-cx:charset:iso-2022-jp'} = {ascii8 =>
1403     '1',
1404     ietf_name =>
1405     ['csiso2022jp',
1406     'iso-2022-jp',
1407     'iso-2022-jp'],
1408     mime_name =>
1409     'iso-2022-jp',
1410     'uri',
1411     {'urn:x-suika-fam-cx:charset:iso-2022-jp',
1412     '1'},
1413 wakaba 1.2 };
1414    
1415 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.iso-2022-jp'} = {ascii8 =>
1416     '1',
1417     perl_name =>
1418     ['iso-2022-jp'],
1419     'uri',
1420     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.iso-2022-jp',
1421     '1'}};
1422     $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 =>
1423     '1',
1424     is_block_safe =>
1425     '1',
1426     ietf_name =>
1427     ['csshiftjis',
1428     'ms_kanji',
1429     'shift_jis',
1430     'shift_jis'],
1431     mime_name =>
1432     'shift_jis',
1433     perl_name =>
1434     ['shift-jis-1997'],
1435     'uri',
1436     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.shift_jis',
1437     '1',
1438     'urn:x-suika-fam-cx:charset:shift_jis',
1439     '1'},
1440 wakaba 1.2 xml_name => 'Shift_JIS',
1441     };
1442    
1443 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.shiftjis'} = {ascii8 =>
1444     '1',
1445     is_block_safe =>
1446     '1',
1447     perl_name =>
1448     ['shiftjis',
1449     'sjis'],
1450     'uri',
1451     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.shiftjis',
1452     '1'}};
1453     $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 =>
1454     '1',
1455     is_block_safe =>
1456     '1',
1457     ietf_name =>
1458     ['cseucpkdfmtjapanese',
1459     'euc-jp',
1460     'euc-jp',
1461     'extended_unix_code_packed_format_for_japanese'],
1462     mime_name =>
1463     'euc-jp',
1464     perl_name =>
1465     ['euc-jp-1997'],
1466     'uri',
1467     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/XML.euc-jp',
1468     '1',
1469     'urn:x-suika-fam-cx:charset:euc-jp',
1470     '1',
1471     'urn:x-suika-fam-cx:charset:extended_unix_code_packed_format_for_japanese',
1472     '1'},
1473 wakaba 1.2 xml_name => 'EUC-JP',
1474     };
1475    
1476 wakaba 1.1 $Whatpm::Charset::CharsetDef->{'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.euc-jp'} = {ascii8 =>
1477     '1',
1478     is_block_safe =>
1479     '1',
1480     perl_name =>
1481     ['euc-jp',
1482     'ujis'],
1483     'uri',
1484     {'http://suika.fam.cx/~wakaba/archive/2004/dis/Charset/Perl.euc-jp',
1485     '1'}};
1486    
1487     1;
1488 wakaba 1.7 ## $Date: 2008/05/18 06:07:22 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24