mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibTextCodec: Bring TextCodec::get_standardized_encoding closer to spec
This commit is contained in:
parent
987910ad0f
commit
09f2d79cb1
Notes:
sideshowbarker
2024-07-16 20:08:14 +09:00
Author: https://github.com/skyrising
Commit: 09f2d79cb1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/32
Reviewed-by: https://github.com/jamierocks
1 changed files with 4 additions and 1 deletions
|
@ -388,8 +388,11 @@ Optional<Decoder&> decoder_for(StringView a_encoding)
|
|||
// https://encoding.spec.whatwg.org/#concept-encoding-get
|
||||
Optional<StringView> get_standardized_encoding(StringView encoding)
|
||||
{
|
||||
encoding = encoding.trim_whitespace();
|
||||
// 1. Remove any leading and trailing ASCII whitespace from label.
|
||||
// https://infra.spec.whatwg.org/#ascii-whitespace: ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE.
|
||||
encoding = encoding.trim("\t\n\f\r "sv);
|
||||
|
||||
// 2. If label is an ASCII case-insensitive match for any of the labels listed in the table below, then return the corresponding encoding; otherwise return failure.
|
||||
if (encoding.is_one_of_ignoring_ascii_case("unicode-1-1-utf-8"sv, "unicode11utf8"sv, "unicode20utf8"sv, "utf-8"sv, "utf8"sv, "x-unicode20utf8"sv))
|
||||
return "UTF-8"sv;
|
||||
if (encoding.is_one_of_ignoring_ascii_case("866"sv, "cp866"sv, "csibm866"sv, "ibm866"sv))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue