mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-20 13:28:13 +03:00
LibTextCodec: Implement UTF8Decoder::to_utf8 using AK::String
String::from_utf8_with_replacement_character is equivalent to https://encoding.spec.whatwg.org/#utf-8-decode from the encoding spec, so we can simply call through to it.
This commit is contained in:
parent
b3bf5c4ea8
commit
0b864bef60
Notes:
github-actions[bot]
2024-08-12 10:39:52 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/0b864bef604 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1038 Reviewed-by: https://github.com/trflynn89
@ -366,16 +366,7 @@ bool UTF8Decoder::validate(StringView input)
|
||||
|
||||
ErrorOr<String> UTF8Decoder::to_utf8(StringView input)
|
||||
{
|
||||
// Discard the BOM
|
||||
auto bomless_input = input;
|
||||
if (auto bytes = input.bytes(); bytes.size() >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF) {
|
||||
bomless_input = input.substring_view(3);
|
||||
}
|
||||
|
||||
if (Utf8View(bomless_input).validate())
|
||||
return String::from_utf8_without_validation(bomless_input.bytes());
|
||||
|
||||
return Decoder::to_utf8(bomless_input);
|
||||
return String::from_utf8_with_replacement_character(input);
|
||||
}
|
||||
|
||||
static Utf16View as_utf16(StringView view, AK::Endianness endianness)
|
||||
|
Loading…
Reference in New Issue
Block a user