summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/Infra/Strings.cpp14
-rw-r--r--Userland/Libraries/LibWeb/Infra/Strings.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Infra/Strings.cpp b/Userland/Libraries/LibWeb/Infra/Strings.cpp
index 130ffaba76..726caddd47 100644
--- a/Userland/Libraries/LibWeb/Infra/Strings.cpp
+++ b/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();
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Infra/Strings.h b/Userland/Libraries/LibWeb/Infra/Strings.h
index 78d8030759..896c2b6b38 100644
--- a/Userland/Libraries/LibWeb/Infra/Strings.h
+++ b/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);
}