mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:37:34 +00:00
LibWeb: Add convert string into scalar value from Infra spec
This commit is contained in:
parent
2ad9c1fd6c
commit
b74d5a423d
2 changed files with 17 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -65,4 +66,18 @@ bool is_code_unit_prefix(StringView potential_prefix, StringView input)
|
|||
}
|
||||
}
|
||||
|
||||
// https://infra.spec.whatwg.org/#scalar-value-string
|
||||
ErrorOr<String> convert_to_scalar_value_string(StringView string)
|
||||
{
|
||||
// To convert a string into a scalar value string, replace any surrogates with U+FFFD.
|
||||
StringBuilder scalar_value_builder;
|
||||
auto utf8_view = Utf8View { string };
|
||||
for (u32 code_point : utf8_view) {
|
||||
if (is_unicode_surrogate(code_point))
|
||||
code_point = 0xFFFD;
|
||||
TRY(scalar_value_builder.try_append(code_point));
|
||||
}
|
||||
return scalar_value_builder.to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue