LibWeb: Add to_ascii_lower_case() from the Infra spec

https://infra.spec.whatwg.org/#ascii-lowercase
This commit is contained in:
Kenneth Myhra 2023-02-25 23:23:26 +01:00 committed by Linus Groh
parent 2facb0e8ed
commit 2c1e15bd3b
Notes: sideshowbarker 2024-07-17 03:35:16 +09:00
2 changed files with 15 additions and 0 deletions

View File

@ -106,4 +106,18 @@ ErrorOr<String> convert_to_scalar_value_string(StringView string)
return scalar_value_builder.to_string();
}
// https://infra.spec.whatwg.org/#ascii-lowercase
ErrorOr<String> to_ascii_lower_case(StringView string)
{
// To ASCII lowercase a string, replace all ASCII upper alphas in the string with their
// corresponding code point in ASCII lower alpha.
StringBuilder string_builder;
auto utf8_view = Utf8View { string };
for (u32 code_point : utf8_view) {
code_point = to_ascii_lowercase(code_point);
TRY(string_builder.try_append(code_point));
}
return string_builder.to_string();
}
}

View File

@ -17,5 +17,6 @@ bool is_ascii_case_insensitive_match(StringView a, StringView b);
DeprecatedString strip_and_collapse_whitespace(StringView string);
bool is_code_unit_prefix(StringView potential_prefix, StringView input);
ErrorOr<String> convert_to_scalar_value_string(StringView string);
ErrorOr<String> to_ascii_lower_case(StringView string);
}