mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb/Infra: Port strip_and_collapse_whitespace() to new String
This commit is contained in:
parent
f65cbeef5c
commit
93ed1b59c8
Notes:
sideshowbarker
2024-07-17 06:46:15 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/93ed1b59c8 Pull-request: https://github.com/SerenityOS/serenity/pull/17718
3 changed files with 8 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/CharacterTypes.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Utf16View.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibWeb/Infra/CharacterTypes.h>
|
||||
|
@ -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<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;
|
||||
|
@ -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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022, networkException <networkexception@serenityos.org>
|
||||
* Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
|
@ -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<String> 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_lowercase(StringView string);
|
||||
|
|
Loading…
Reference in a new issue