mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
LibTextCodec: Add "get output encoding" from the Encoding specification
This commit is contained in:
parent
a53486a073
commit
eaa4048870
2 changed files with 13 additions and 0 deletions
|
@ -221,6 +221,17 @@ ErrorOr<String> convert_input_to_utf8_using_given_decoder_unless_there_is_a_byte
|
|||
return output;
|
||||
}
|
||||
|
||||
// https://encoding.spec.whatwg.org/#get-an-output-encoding
|
||||
StringView get_output_encoding(StringView encoding)
|
||||
{
|
||||
// 1. If encoding is replacement or UTF-16BE/LE, then return UTF-8.
|
||||
if (encoding.is_one_of_ignoring_ascii_case("replacement"sv, "utf-16le"sv, "utf-16be"sv))
|
||||
return "UTF-8"sv;
|
||||
|
||||
// 2. Return encoding.
|
||||
return encoding;
|
||||
}
|
||||
|
||||
ErrorOr<String> Decoder::to_utf8(StringView input)
|
||||
{
|
||||
StringBuilder builder(input.length());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue