From 93ed1b59c885a600987b0db508f1bac43b1c437f Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 4 Mar 2023 21:42:38 +0000 Subject: [PATCH] LibWeb/Infra: Port strip_and_collapse_whitespace() to new String --- Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp | 2 +- Userland/Libraries/LibWeb/Infra/Strings.cpp | 10 +++++----- Userland/Libraries/LibWeb/Infra/Strings.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index 72d3f1036de..9fc068cd4dd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -108,7 +108,7 @@ DeprecatedString HTMLOptionElement::text() const }); // Return the result of stripping and collapsing ASCII whitespace from the above concatenation. - return Infra::strip_and_collapse_whitespace(builder.string_view()); + return Infra::strip_and_collapse_whitespace(builder.string_view()).release_value_but_fixme_should_propagate_errors().to_deprecated_string(); } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text diff --git a/Userland/Libraries/LibWeb/Infra/Strings.cpp b/Userland/Libraries/LibWeb/Infra/Strings.cpp index 09e7c2ad230..793dfb2213b 100644 --- a/Userland/Libraries/LibWeb/Infra/Strings.cpp +++ b/Userland/Libraries/LibWeb/Infra/Strings.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Linus Groh + * Copyright (c) 2022-2023, Linus Groh * Copyright (c) 2022, networkException * Copyright (c) 2023, Kenneth Myhra * Copyright (c) 2023, Sam Atkins @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include #include @@ -41,7 +41,7 @@ bool is_ascii_case_insensitive_match(StringView a, StringView b) } // https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace -DeprecatedString strip_and_collapse_whitespace(StringView string) +ErrorOr strip_and_collapse_whitespace(StringView string) { // Replace any sequence of one or more consecutive code points that are ASCII whitespace in the string with a single U+0020 SPACE code point. StringBuilder builder; @@ -51,11 +51,11 @@ DeprecatedString strip_and_collapse_whitespace(StringView string) builder.append(' '); continue; } - builder.append_code_point(code_point); + TRY(builder.try_append_code_point(code_point)); } // ...and then remove any leading and trailing ASCII whitespace from that string. - return builder.string_view().trim(Infra::ASCII_WHITESPACE); + return String::from_utf8(builder.string_view().trim(Infra::ASCII_WHITESPACE)); } // https://infra.spec.whatwg.org/#code-unit-prefix diff --git a/Userland/Libraries/LibWeb/Infra/Strings.h b/Userland/Libraries/LibWeb/Infra/Strings.h index 7712f19dfa5..b13fb90a3bc 100644 --- a/Userland/Libraries/LibWeb/Infra/Strings.h +++ b/Userland/Libraries/LibWeb/Infra/Strings.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Linus Groh + * Copyright (c) 2022-2023, Linus Groh * Copyright (c) 2022, networkException * Copyright (c) 2023, Kenneth Myhra * Copyright (c) 2023, Sam Atkins @@ -14,7 +14,7 @@ namespace Web::Infra { bool is_ascii_case_insensitive_match(StringView a, StringView b); -DeprecatedString strip_and_collapse_whitespace(StringView string); +ErrorOr strip_and_collapse_whitespace(StringView string); bool is_code_unit_prefix(StringView potential_prefix, StringView input); ErrorOr convert_to_scalar_value_string(StringView string); ErrorOr to_ascii_lowercase(StringView string);