Parent Directory
|
Revision Log
|
Patch
| revision 1.153 by wakaba, Fri Aug 15 08:32:41 2008 UTC | revision 1.161 by wakaba, Wed Sep 10 10:46:50 2008 UTC | |
|---|---|---|
| # | Line 372 sub parse_byte_stream ($$$$;$) { | Line 372 sub parse_byte_stream ($$$$;$) { |
| 372 | my ($char_stream, $e_status); | my ($char_stream, $e_status); |
| 373 | ||
| 374 | SNIFFING: { | SNIFFING: { |
| 375 | ## NOTE: By setting |allow_fallback| option true when the | |
| 376 | ## |get_decode_handle| method is invoked, we ignore what the HTML5 | |
| 377 | ## spec requires, i.e. unsupported encoding should be ignored. | |
| 378 | ## TODO: We should not do this unless the parser is invoked | |
| 379 | ## in the conformance checking mode, in which this behavior | |
| 380 | ## would be useful. | |
| 381 | ||
| 382 | ## Step 1 | ## Step 1 |
| 383 | if (defined $charset_name) { | if (defined $charset_name) { |
| 384 | $charset = Message::Charset::Info->get_by_iana_name ($charset_name); | $charset = Message::Charset::Info->get_by_html_name ($charset_name); |
| 385 | ## TODO: Is this ok? Transfer protocol's parameter should be | |
| 386 | ## interpreted in its semantics? | |
| 387 | ||
| 388 | ## ISSUE: Unsupported encoding is not ignored according to the spec. | ## ISSUE: Unsupported encoding is not ignored according to the spec. |
| 389 | ($char_stream, $e_status) = $charset->get_decode_handle | ($char_stream, $e_status) = $charset->get_decode_handle |
| # | Line 399 sub parse_byte_stream ($$$$;$) { | Line 407 sub parse_byte_stream ($$$$;$) { |
| 407 | ||
| 408 | ## Step 3 | ## Step 3 |
| 409 | if ($byte_buffer =~ /^\xFE\xFF/) { | if ($byte_buffer =~ /^\xFE\xFF/) { |
| 410 | $charset = Message::Charset::Info->get_by_iana_name ('utf-16be'); | $charset = Message::Charset::Info->get_by_html_name ('utf-16be'); |
| 411 | ($char_stream, $e_status) = $charset->get_decode_handle | ($char_stream, $e_status) = $charset->get_decode_handle |
| 412 | ($byte_stream, allow_error_reporting => 1, | ($byte_stream, allow_error_reporting => 1, |
| 413 | allow_fallback => 1, byte_buffer => \$byte_buffer); | allow_fallback => 1, byte_buffer => \$byte_buffer); |
| 414 | $self->{confident} = 1; | $self->{confident} = 1; |
| 415 | last SNIFFING; | last SNIFFING; |
| 416 | } elsif ($byte_buffer =~ /^\xFF\xFE/) { | } elsif ($byte_buffer =~ /^\xFF\xFE/) { |
| 417 | $charset = Message::Charset::Info->get_by_iana_name ('utf-16le'); | $charset = Message::Charset::Info->get_by_html_name ('utf-16le'); |
| 418 | ($char_stream, $e_status) = $charset->get_decode_handle | ($char_stream, $e_status) = $charset->get_decode_handle |
| 419 | ($byte_stream, allow_error_reporting => 1, | ($byte_stream, allow_error_reporting => 1, |
| 420 | allow_fallback => 1, byte_buffer => \$byte_buffer); | allow_fallback => 1, byte_buffer => \$byte_buffer); |
| 421 | $self->{confident} = 1; | $self->{confident} = 1; |
| 422 | last SNIFFING; | last SNIFFING; |
| 423 | } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) { | } elsif ($byte_buffer =~ /^\xEF\xBB\xBF/) { |
| 424 | $charset = Message::Charset::Info->get_by_iana_name ('utf-8'); | $charset = Message::Charset::Info->get_by_html_name ('utf-8'); |
| 425 | ($char_stream, $e_status) = $charset->get_decode_handle | ($char_stream, $e_status) = $charset->get_decode_handle |
| 426 | ($byte_stream, allow_error_reporting => 1, | ($byte_stream, allow_error_reporting => 1, |
| 427 | allow_fallback => 1, byte_buffer => \$byte_buffer); | allow_fallback => 1, byte_buffer => \$byte_buffer); |
| # | Line 432 sub parse_byte_stream ($$$$;$) { | Line 440 sub parse_byte_stream ($$$$;$) { |
| 440 | $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string | $charset_name = Whatpm::Charset::UniversalCharDet->detect_byte_string |
| 441 | ($byte_buffer); | ($byte_buffer); |
| 442 | if (defined $charset_name) { | if (defined $charset_name) { |
| 443 | $charset = Message::Charset::Info->get_by_iana_name ($charset_name); | $charset = Message::Charset::Info->get_by_html_name ($charset_name); |
| 444 | ||
| 445 | ## ISSUE: Unsupported encoding is not ignored according to the spec. | ## ISSUE: Unsupported encoding is not ignored according to the spec. |
| 446 | require Whatpm::Charset::DecodeHandle; | require Whatpm::Charset::DecodeHandle; |
| # | Line 455 sub parse_byte_stream ($$$$;$) { | Line 463 sub parse_byte_stream ($$$$;$) { |
| 463 | ||
| 464 | ## Step 7: default | ## Step 7: default |
| 465 | ## TODO: Make this configurable. | ## TODO: Make this configurable. |
| 466 | $charset = Message::Charset::Info->get_by_iana_name ('windows-1252'); | $charset = Message::Charset::Info->get_by_html_name ('windows-1252'); |
| 467 | ## NOTE: We choose |windows-1252| here, since |utf-8| should be | ## NOTE: We choose |windows-1252| here, since |utf-8| should be |
| 468 | ## detectable in the step 6. | ## detectable in the step 6. |
| 469 | require Whatpm::Charset::DecodeHandle; | require Whatpm::Charset::DecodeHandle; |
| # | Line 475 sub parse_byte_stream ($$$$;$) { | Line 483 sub parse_byte_stream ($$$$;$) { |
| 483 | $self->{confident} = 0; | $self->{confident} = 0; |
| 484 | } # SNIFFING | } # SNIFFING |
| 485 | ||
| $self->{input_encoding} = $charset->get_iana_name; | ||
| 486 | if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) { | if ($e_status & Message::Charset::Info::FALLBACK_ENCODING_IMPL ()) { |
| 487 | $self->{input_encoding} = $charset->get_iana_name; ## TODO: Should we set actual charset decoder's encoding name? | |
| 488 | !!!parse-error (type => 'chardecode:fallback', | !!!parse-error (type => 'chardecode:fallback', |
| 489 | text => $self->{input_encoding}, | #text => $self->{input_encoding}, |
| 490 | level => $self->{level}->{uncertain}, | level => $self->{level}->{uncertain}, |
| 491 | line => 1, column => 1, | line => 1, column => 1, |
| 492 | layer => 'encode'); | layer => 'encode'); |
| 493 | } elsif (not ($e_status & | } elsif (not ($e_status & |
| 494 | Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) { | Message::Charset::Info::ERROR_REPORTING_ENCODING_IMPL())) { |
| 495 | $self->{input_encoding} = $charset->get_iana_name; | |
| 496 | !!!parse-error (type => 'chardecode:no error', | !!!parse-error (type => 'chardecode:no error', |
| 497 | text => $self->{input_encoding}, | text => $self->{input_encoding}, |
| 498 | level => $self->{level}->{uncertain}, | level => $self->{level}->{uncertain}, |
| 499 | line => 1, column => 1, | line => 1, column => 1, |
| 500 | layer => 'encode'); | layer => 'encode'); |
| 501 | } else { | |
| 502 | $self->{input_encoding} = $charset->get_iana_name; | |
| 503 | } | } |
| 504 | ||
| 505 | $self->{change_encoding} = sub { | $self->{change_encoding} = sub { |
| # | Line 496 sub parse_byte_stream ($$$$;$) { | Line 507 sub parse_byte_strea |