mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
AK: Add BOM handling to String::from_utf8_with_replacement_character
This commit is contained in:
parent
1e8cc97b73
commit
b3bf5c4ea8
Notes:
github-actions[bot]
2024-08-12 10:39:57 +00:00
Author: https://github.com/shannonbooth
Commit: b3bf5c4ea8
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1038
Reviewed-by: https://github.com/trflynn89
4 changed files with 21 additions and 7 deletions
|
@ -20,8 +20,11 @@
|
|||
|
||||
namespace AK {
|
||||
|
||||
String String::from_utf8_with_replacement_character(StringView view)
|
||||
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)
|
||||
view = view.substring_view(3);
|
||||
|
||||
if (Utf8View(view).validate())
|
||||
return String::from_utf8_without_validation(view.bytes());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue