1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

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
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();
}
}