From bee32b6cd23e8cfb4cc4f2ad1c691f457d7f4e45 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 15 Feb 2023 11:28:23 +0000 Subject: [PATCH] LibWeb: Port CSS::Parser::Declaration to new Strings --- .../Libraries/LibWeb/CSS/Parser/Declaration.cpp | 14 +++++++------- Userland/Libraries/LibWeb/CSS/Parser/Declaration.h | 9 +++++---- .../LibWeb/CSS/Parser/DeclarationOrAtRule.cpp | 2 +- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Declaration.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Declaration.cpp index e38aa497fa..1ae3732321 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Declaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Declaration.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2022, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,7 +10,7 @@ namespace Web::CSS::Parser { -Declaration::Declaration(DeprecatedFlyString name, Vector values, Important important) +Declaration::Declaration(FlyString name, Vector values, Important important) : m_name(move(name)) , m_values(move(values)) , m_important(move(important)) @@ -19,18 +19,18 @@ Declaration::Declaration(DeprecatedFlyString name, Vector values Declaration::~Declaration() = default; -DeprecatedString Declaration::to_deprecated_string() const +ErrorOr Declaration::to_string() const { StringBuilder builder; serialize_an_identifier(builder, m_name); - builder.append(": "sv); - builder.join(' ', m_values); + TRY(builder.try_append(": "sv)); + TRY(builder.try_join(' ', m_values)); if (m_important == Important::Yes) - builder.append(" !important"sv); + TRY(builder.try_append(" !important"sv)); - return builder.to_deprecated_string(); + return builder.to_string(); } } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Declaration.h b/Userland/Libraries/LibWeb/CSS/Parser/Declaration.h index 35f0dc1a6c..a8da2664e2 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Declaration.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Declaration.h @@ -1,12 +1,13 @@ /* * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2022-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include +#include #include #include #include @@ -15,17 +16,17 @@ namespace Web::CSS::Parser { class Declaration { public: - Declaration(DeprecatedFlyString name, Vector values, Important); + Declaration(FlyString name, Vector values, Important); ~Declaration(); StringView name() const { return m_name; } Vector const& values() const { return m_values; } Important importance() const { return m_important; } - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; private: - DeprecatedFlyString m_name; + FlyString m_name; Vector m_values; Important m_important { Important::No }; }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.cpp b/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.cpp index e26ee5ec28..cee9589a9e 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/DeclarationOrAtRule.cpp @@ -33,7 +33,7 @@ DeprecatedString DeclarationOrAtRule::to_deprecated_string() const builder.append(m_at->to_deprecated_string()); break; case DeclarationType::Declaration: - builder.append(m_declaration->to_deprecated_string()); + builder.append(m_declaration->to_string().release_value_but_fixme_should_propagate_errors()); break; } diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 2b12a82016..ebcee80605 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1395,7 +1395,7 @@ Optional Parser::parse_supports_feature(TokenStreamto_deprecated_string() } + Supports::Declaration { declaration->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string() } }; } } @@ -1856,7 +1856,7 @@ Optional Parser::consume_a_declaration(TokenStream& tokens) // Create a new declaration with its name set to the value of the current input token // and its value initially set to the empty list. // NOTE: We create a fully-initialized Declaration just before returning it instead. - DeprecatedFlyString declaration_name = ((Token)token).ident(); + auto declaration_name = FlyString::from_utf8(((Token)token).ident()).release_value_but_fixme_should_propagate_errors(); Vector declaration_values; Important declaration_important = Important::No;