mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibTextCodec+LibWeb: Move isomorphic coders to LibTextCodec
This will be used outside of LibWeb.
This commit is contained in:
parent
0480934afb
commit
0fd80a8f99
Notes:
github-actions[bot]
2025-11-27 13:59:06 +00:00
Author: https://github.com/trflynn89
Commit: 0fd80a8f99
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6944
Reviewed-by: https://github.com/gmta ✅
17 changed files with 65 additions and 64 deletions
|
|
@ -156,39 +156,6 @@ ErrorOr<String> convert_to_scalar_value_string(StringView string)
|
|||
return scalar_value_builder.to_string();
|
||||
}
|
||||
|
||||
// https://infra.spec.whatwg.org/#isomorphic-encode
|
||||
ByteString isomorphic_encode(StringView input)
|
||||
{
|
||||
// To isomorphic encode an isomorphic string input: return a byte sequence whose length is equal to input’s code
|
||||
// point length and whose bytes have the same values as the values of input’s code points, in the same order.
|
||||
// NB: This is essentially spec-speak for "Encode as ISO-8859-1 / Latin-1".
|
||||
StringBuilder builder(input.length());
|
||||
|
||||
for (auto code_point : Utf8View { input }) {
|
||||
// VERIFY(code_point <= 0xFF);
|
||||
if (code_point > 0xFF)
|
||||
dbgln("FIXME: Trying to isomorphic encode a string with code points > U+00FF.");
|
||||
|
||||
builder.append(static_cast<u8>(code_point));
|
||||
}
|
||||
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
// https://infra.spec.whatwg.org/#isomorphic-decode
|
||||
String isomorphic_decode(StringView input)
|
||||
{
|
||||
// To isomorphic decode a byte sequence input, return a string whose code point length is equal to input’s length
|
||||
// and whose code points have the same values as the values of input’s bytes, in the same order.
|
||||
// NB: This is essentially spec-speak for "Decode as ISO-8859-1 / Latin-1".
|
||||
StringBuilder builder(input.length());
|
||||
|
||||
for (auto byte : input.bytes())
|
||||
builder.append_code_point(byte);
|
||||
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
// https://infra.spec.whatwg.org/#code-unit-less-than
|
||||
bool code_unit_less_than(StringView a, StringView b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ WEB_API ErrorOr<String> strip_and_collapse_whitespace(StringView string);
|
|||
Utf16String strip_and_collapse_whitespace(Utf16String const& string);
|
||||
WEB_API bool is_code_unit_prefix(StringView potential_prefix, StringView input);
|
||||
WEB_API ErrorOr<String> convert_to_scalar_value_string(StringView string);
|
||||
ByteString isomorphic_encode(StringView input);
|
||||
WEB_API String isomorphic_decode(StringView input);
|
||||
bool code_unit_less_than(StringView a, StringView b);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue