| 525 |
|
|
| 526 |
if ($char_stream) { # if supported |
if ($char_stream) { # if supported |
| 527 |
## "Change the encoding" algorithm: |
## "Change the encoding" algorithm: |
|
|
|
|
## Step 1 |
|
|
if ($charset->{category} & |
|
|
Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) { |
|
|
$charset = Message::Charset::Info->get_by_html_name ('utf-8'); |
|
|
($char_stream, $e_status) = $charset->get_decode_handle |
|
|
($byte_stream, |
|
|
byte_buffer => \ $buffer->{buffer}); |
|
|
} |
|
|
$charset_name = $charset->get_iana_name; |
|
| 528 |
|
|
| 529 |
## Step 2 |
## Step 1 |
| 530 |
if (defined $self->{input_encoding} and |
if (defined $self->{input_encoding} and |
| 531 |
$self->{input_encoding} eq $charset_name) { |
$self->{input_encoding} eq $charset_name) { |
| 532 |
!!!parse-error (type => 'charset label:matching', |
!!!parse-error (type => 'charset label:matching', |
| 536 |
return; |
return; |
| 537 |
} |
} |
| 538 |
|
|
| 539 |
|
## Step 2 (HTML5 revision 3205) |
| 540 |
|
if (defined $self->{input_encoding} and |
| 541 |
|
Message::Charset::Info->get_by_html_name ($self->{input_encoding}) |
| 542 |
|
->{category} & Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) { |
| 543 |
|
$self->{confident} = 1; |
| 544 |
|
return; |
| 545 |
|
} |
| 546 |
|
|
| 547 |
|
## Step 3 |
| 548 |
|
if ($charset->{category} & |
| 549 |
|
Message::Charset::Info::CHARSET_CATEGORY_UTF16 ()) { |
| 550 |
|
$charset = Message::Charset::Info->get_by_html_name ('utf-8'); |
| 551 |
|
($char_stream, $e_status) = $charset->get_decode_handle |
| 552 |
|
($byte_stream, |
| 553 |
|
byte_buffer => \ $buffer->{buffer}); |
| 554 |
|
} |
| 555 |
|
$charset_name = $charset->get_iana_name; |
| 556 |
|
|
| 557 |
!!!parse-error (type => 'charset label detected', |
!!!parse-error (type => 'charset label detected', |
| 558 |
text => $self->{input_encoding}, |
text => $self->{input_encoding}, |
| 559 |
value => $charset_name, |
value => $charset_name, |
| 560 |
level => $self->{level}->{warn}, |
level => $self->{level}->{warn}, |
| 561 |
token => $token); |
token => $token); |
| 562 |
|
|
| 563 |
## Step 3 |
## Step 4 |
| 564 |
# if (can) { |
# if (can) { |
| 565 |
## change the encoding on the fly. |
## change the encoding on the fly. |
| 566 |
#$self->{confident} = 1; |
#$self->{confident} = 1; |
| 567 |
#return; |
#return; |
| 568 |
# } |
# } |
| 569 |
|
|
| 570 |
## Step 4 |
## Step 5 |
| 571 |
throw Whatpm::HTML::RestartParser (); |
throw Whatpm::HTML::RestartParser (); |
| 572 |
} |
} |
| 573 |
}; # $self->{change_encoding} |
}; # $self->{change_encoding} |