summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/HTML
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-10-01 18:39:40 +0100
committerAndreas Kling <kling@serenityos.org>2022-10-02 21:32:49 +0200
commit7760c007140f8acbd6f214898a7c8e7a565f4875 (patch)
treeb959881311191d55af97323319a46f0925e90fcf /Userland/Libraries/LibWeb/HTML
parentb86c26497565164bfc4109b1095f1eb424de0dc7 (diff)
downloadserenity-7760c007140f8acbd6f214898a7c8e7a565f4875.zip
LibWeb: Move strip_and_collapse_whitespace() to Infra/
...and make it spec compliant by considering all ASCII whitespace, greatly simplifying it in the process :^)
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp30
1 files changed, 2 insertions, 28 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
index 30022010d0..270337d22d 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
@@ -13,8 +13,7 @@
#include <LibWeb/HTML/HTMLOptionElement.h>
#include <LibWeb/HTML/HTMLScriptElement.h>
#include <LibWeb/HTML/HTMLSelectElement.h>
-#include <LibWeb/Infra/CharacterTypes.h>
-#include <ctype.h>
+#include <LibWeb/Infra/Strings.h>
namespace Web::HTML {
@@ -76,31 +75,6 @@ void HTMLOptionElement::set_value(String value)
set_attribute(HTML::AttributeNames::value, value);
}
-// https://infra.spec.whatwg.org/#strip-and-collapse-ascii-whitespace
-static String 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;
- for (size_t i = 0; i < string.length(); ++i) {
- if (isspace(string[i])) {
- builder.append(' ');
- while (i < string.length()) {
- if (isspace(string[i])) {
- ++i;
- continue;
- }
- builder.append(string[i]);
- break;
- }
- continue;
- }
- builder.append(string[i]);
- }
-
- // ...and then remove any leading and trailing ASCII whitespace from that string.
- return builder.to_string().trim(Infra::ASCII_WHITESPACE);
-}
-
static void concatenate_descendants_text_content(DOM::Node const* node, StringBuilder& builder)
{
// FIXME: SVGScriptElement should also be skipped, but it doesn't exist yet.
@@ -126,7 +100,7 @@ String HTMLOptionElement::text() const
});
// Return the result of stripping and collapsing ASCII whitespace from the above concatenation.
- return strip_and_collapse_whitespace(builder.to_string());
+ return Infra::strip_and_collapse_whitespace(builder.string_view());
}
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text