From 0b864bef6040fa66f6719bf06898e310d4c5c02f Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 11 Aug 2024 15:02:55 +1200 Subject: [PATCH] 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. --- Userland/Libraries/LibTextCodec/Decoder.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Userland/Libraries/LibTextCodec/Decoder.cpp b/Userland/Libraries/LibTextCodec/Decoder.cpp index 43d47478d54..c9c111a29bf 100644 --- a/Userland/Libraries/LibTextCodec/Decoder.cpp +++ b/Userland/Libraries/LibTextCodec/Decoder.cpp @@ -366,16 +366,7 @@ bool UTF8Decoder::validate(StringView input) ErrorOr 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)