mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +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, Linus Groh <linusg@serenityos.org>
|
||||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||||
|
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* 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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||||
|
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -13,5 +14,6 @@ namespace Web::Infra {
|
||||||
|
|
||||||
DeprecatedString strip_and_collapse_whitespace(StringView string);
|
DeprecatedString strip_and_collapse_whitespace(StringView string);
|
||||||
bool is_code_unit_prefix(StringView potential_prefix, StringView input);
|
bool is_code_unit_prefix(StringView potential_prefix, StringView input);
|
||||||
|
ErrorOr<String> convert_to_scalar_value_string(StringView string);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue