diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2023-02-14 18:55:59 +0000 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-02-15 12:48:26 -0500 |
commit | 05c1b0962184d00ff140063d61c9317dcdca9a31 (patch) | |
tree | 1826002eef8b8bff7a5c1b7ff2cb5b14907c53a8 /Userland | |
parent | 86d23c63a49dd5493e5ee9801cc92b0403907b25 (diff) | |
download | serenity-05c1b0962184d00ff140063d61c9317dcdca9a31.zip |
LibWeb: Port CSS::Parser::Function to new Strings
Diffstat (limited to 'Userland')
5 files changed, 20 insertions, 19 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp index 9b9a4adca4..2505db04e7 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp @@ -31,7 +31,7 @@ DeprecatedString ComponentValue::to_deprecated_string() const return m_value.visit( [](Token const& token) { return token.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); }, [](NonnullRefPtr<Block> const& block) { return block->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); }, - [](NonnullRefPtr<Function> const& function) { return function->to_deprecated_string(); }); + [](NonnullRefPtr<Function> const& function) { return function->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); }); } ErrorOr<String> ComponentValue::to_debug_string() const @@ -44,7 +44,7 @@ ErrorOr<String> ComponentValue::to_debug_string() const return String::formatted("Block: {}", TRY(block->to_string())); }, [](NonnullRefPtr<Function> const& function) -> ErrorOr<String> { - return String::formatted("Function: {}", function->to_deprecated_string()); + return String::formatted("Function: {}", TRY(function->to_string())); }); } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp index 8d4a06c139..e5e8a935ab 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,7 +10,7 @@ namespace Web::CSS::Parser { -Function::Function(DeprecatedFlyString name, Vector<ComponentValue>&& values) +Function::Function(FlyString name, Vector<ComponentValue>&& values) : m_name(move(name)) , m_values(move(values)) { @@ -18,16 +18,16 @@ Function::Function(DeprecatedFlyString name, Vector<ComponentValue>&& values) Function::~Function() = default; -DeprecatedString Function::to_deprecated_string() const +ErrorOr<String> Function::to_string() const { StringBuilder builder; serialize_an_identifier(builder, m_name); - builder.append('('); - builder.join(' ', m_values); - builder.append(')'); + TRY(builder.try_append('(')); + TRY(builder.try_join(' ', m_values)); + TRY(builder.try_append(')')); - return builder.to_deprecated_string(); + return builder.to_string(); } } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Function.h b/Userland/Libraries/LibWeb/CSS/Parser/Function.h index 6eb161bbc8..88928b7b49 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Function.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Function.h @@ -1,15 +1,15 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org> + * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org> * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include <AK/DeprecatedFlyString.h> -#include <AK/DeprecatedString.h> +#include <AK/FlyString.h> #include <AK/RefCounted.h> +#include <AK/String.h> #include <AK/Vector.h> #include <LibWeb/CSS/Parser/ComponentValue.h> #include <LibWeb/Forward.h> @@ -18,7 +18,7 @@ namespace Web::CSS::Parser { class Function : public RefCounted<Function> { public: - static NonnullRefPtr<Function> create(DeprecatedFlyString name, Vector<ComponentValue>&& values) + static NonnullRefPtr<Function> create(FlyString name, Vector<ComponentValue>&& values) { return adopt_ref(*new Function(move(name), move(values))); } @@ -28,12 +28,12 @@ public: StringView name() const { return m_name; } Vector<ComponentValue> const& values() const { return m_values; } - DeprecatedString to_deprecated_string() const; + ErrorOr<String> to_string() const; private: - Function(DeprecatedFlyString name, Vector<ComponentValue>&& values); + Function(FlyString name, Vector<ComponentValue>&& values); - DeprecatedFlyString m_name; + FlyString m_name; Vector<ComponentValue> m_values; }; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index f264d30c24..e433e50ad2 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1801,7 +1801,7 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens) // Create a function with its name equal to the value of the current input token // and with its value initially set to an empty list. // NOTE: We create the Function fully initialized when we return it instead. - DeprecatedFlyString function_name = ((Token)name_ident).function(); + auto function_name = FlyString::from_utf8(((Token)name_ident).function()).release_value_but_fixme_should_propagate_errors(); Vector<ComponentValue> function_values; // Repeatedly consume the next input token and process it as follows: diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index a672475399..4dbb41256a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -628,7 +628,7 @@ bool StyleComputer::expand_variables(DOM::Element& element, StringView property_ Parser::TokenStream source_function_contents { source_function.values() }; if (!expand_variables(element, property_name, dependencies, source_function_contents, function_values)) return false; - NonnullRefPtr<Parser::Function> function = Parser::Function::create(source_function.name(), move(function_values)); + NonnullRefPtr<Parser::Function> function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values)); dest.empend(function); continue; } @@ -750,7 +750,8 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p Parser::TokenStream source_function_contents { source_function.values() }; if (!expand_unresolved_values(element, property_name, source_function_contents, function_values)) return false; - NonnullRefPtr<Parser::Function> function = Parser::Function::create(source_function.name(), move(function_values)); + // FIXME: This would be much nicer if we could access the source_function's FlyString value directly. + NonnullRefPtr<Parser::Function> function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values)); dest.empend(function); continue; } |