AK: Simplify BOM parsing in String::from_utf8_with_replacement_character

This commit is contained in:
Timothy Flynn 2025-07-05 11:48:43 -04:00 committed by Shannon Booth
commit 51afbf5280
Notes: github-actions[bot] 2025-07-05 16:31:25 +00:00

View file

@ -24,7 +24,7 @@ namespace AK {
String String::from_utf8_with_replacement_character(StringView view, WithBOMHandling with_bom_handling)
{
if (auto bytes = view.bytes(); with_bom_handling == WithBOMHandling::Yes && bytes.size() >= 3 && bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
if (auto bytes = view.bytes(); with_bom_handling == WithBOMHandling::Yes && bytes.starts_with({ { 0xEF, 0xBB, 0xBF } }))
view = view.substring_view(3);
if (Utf8View(view).validate())