1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-22 12:07:39 +00:00

LibWeb: Port CSS::Parser::Declaration to new Strings

This commit is contained in:
Sam Atkins 2023-02-15 11:28:23 +00:00 committed by Tim Flynn
parent a168cda4a7
commit bee32b6cd2
4 changed files with 15 additions and 14 deletions

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2020-2021, the SerenityOS developers. * 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 * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -10,7 +10,7 @@
namespace Web::CSS::Parser { namespace Web::CSS::Parser {
Declaration::Declaration(DeprecatedFlyString name, Vector<ComponentValue> values, Important important) Declaration::Declaration(FlyString name, Vector<ComponentValue> values, Important important)
: m_name(move(name)) : m_name(move(name))
, m_values(move(values)) , m_values(move(values))
, m_important(move(important)) , m_important(move(important))
@ -19,18 +19,18 @@ Declaration::Declaration(DeprecatedFlyString name, Vector<ComponentValue> values
Declaration::~Declaration() = default; Declaration::~Declaration() = default;
DeprecatedString Declaration::to_deprecated_string() const ErrorOr<String> Declaration::to_string() const
{ {
StringBuilder builder; StringBuilder builder;
serialize_an_identifier(builder, m_name); serialize_an_identifier(builder, m_name);
builder.append(": "sv); TRY(builder.try_append(": "sv));
builder.join(' ', m_values); TRY(builder.try_join(' ', m_values));
if (m_important == Important::Yes) if (m_important == Important::Yes)
builder.append(" !important"sv); TRY(builder.try_append(" !important"sv));
return builder.to_deprecated_string(); return builder.to_string();
} }
} }

View file

@ -1,12 +1,13 @@
/* /*
* Copyright (c) 2020-2021, the SerenityOS developers. * Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#pragma once #pragma once
#include <AK/DeprecatedString.h> #include <AK/FlyString.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibWeb/CSS/CSSStyleDeclaration.h> #include <LibWeb/CSS/CSSStyleDeclaration.h>
#include <LibWeb/CSS/Parser/ComponentValue.h> #include <LibWeb/CSS/Parser/ComponentValue.h>
@ -15,17 +16,17 @@ namespace Web::CSS::Parser {
class Declaration { class Declaration {
public: public:
Declaration(DeprecatedFlyString name, Vector<ComponentValue> values, Important); Declaration(FlyString name, Vector<ComponentValue> values, Important);
~Declaration(); ~Declaration();
StringView name() const { return m_name; } StringView name() const { return m_name; }
Vector<ComponentValue> const& values() const { return m_values; } Vector<ComponentValue> const& values() const { return m_values; }
Important importance() const { return m_important; } Important importance() const { return m_important; }
DeprecatedString to_deprecated_string() const; ErrorOr<String> to_string() const;
private: private:
DeprecatedFlyString m_name; FlyString m_name;
Vector<ComponentValue> m_values; Vector<ComponentValue> m_values;
Important m_important { Important::No }; Important m_important { Important::No };
}; };

View file

@ -33,7 +33,7 @@ DeprecatedString DeclarationOrAtRule::to_deprecated_string() const
builder.append(m_at->to_deprecated_string()); builder.append(m_at->to_deprecated_string());
break; break;
case DeclarationType::Declaration: case DeclarationType::Declaration:
builder.append(m_declaration->to_deprecated_string()); builder.append(m_declaration->to_string().release_value_but_fixme_should_propagate_errors());
break; break;
} }

View file

@ -1395,7 +1395,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) { if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
transaction.commit(); transaction.commit();
return Supports::Feature { return Supports::Feature {
Supports::Declaration { declaration->to_deprecated_string() } Supports::Declaration { declaration->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string() }
}; };
} }
} }
@ -1856,7 +1856,7 @@ Optional<Declaration> Parser::consume_a_declaration(TokenStream<T>& tokens)
// Create a new declaration with its name set to the value of the current input token // 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. // and its value initially set to the empty list.
// NOTE: We create a fully-initialized Declaration just before returning it instead. // 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<ComponentValue> declaration_values; Vector<ComponentValue> declaration_values;
Important declaration_important = Important::No; Important declaration_important = Important::No;