/[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.4 - (hide annotations) (download)
Sun May 18 03:46:30 2008 UTC (17 years, 1 month ago) by wakaba
Branch: MAIN
Changes since 1.3: +10 -1 lines
++ whatpm/Whatpm/ChangeLog	18 May 2008 03:46:02 -0000
2008-05-18  Wakaba  <wakaba@suika.fam.cx>

	* HTML.pm.src (parse_byte_string): Fix the column number reported
	by encoding layer error reporter.

++ whatpm/Whatpm/Charset/ChangeLog	18 May 2008 03:46:17 -0000
2008-05-18  Wakaba  <wakaba@suika.fam.cx>

	* DecodeHandle.pm (getc): Ignore BOM if BOM pattern is specified.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24