Browse Source

LibWeb: Add to_ascii_upper_case() from the Infra spec

https://infra.spec.whatwg.org/#ascii-uppercase
Kenneth Myhra 2 năm trước cách đây
mục cha
commit
31a9bd2bfd

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

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

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

@@ -18,5 +18,6 @@ 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);
+ErrorOr<String> to_ascii_upper_case(StringView string);
 
 }