Переглянути джерело

LibWeb: Add to_ascii_lower_case() from the Infra spec

https://infra.spec.whatwg.org/#ascii-lowercase
Kenneth Myhra 2 роки тому
батько
коміт
2c1e15bd3b

+ 14 - 0
Userland/Libraries/LibWeb/Infra/Strings.cpp

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

+ 1 - 0
Userland/Libraries/LibWeb/Infra/Strings.h

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