mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +00:00
LibWeb: Port CSS::Parser::Declaration to new Strings
This commit is contained in:
parent
a168cda4a7
commit
bee32b6cd2
4 changed files with 15 additions and 14 deletions
|
@ -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 {
|
||||
|
||||
Declaration::Declaration(DeprecatedFlyString name, Vector<ComponentValue> values, Important important)
|
||||
Declaration::Declaration(FlyString name, Vector<ComponentValue> values, Important important)
|
||||
: m_name(move(name))
|
||||
, m_values(move(values))
|
||||
, m_important(move(important))
|
||||
|
@ -19,18 +19,18 @@ Declaration::Declaration(DeprecatedFlyString name, Vector<ComponentValue> values
|
|||
|
||||
Declaration::~Declaration() = default;
|
||||
|
||||
DeprecatedString Declaration::to_deprecated_string() const
|
||||
ErrorOr<String> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
|
@ -15,17 +16,17 @@ namespace Web::CSS::Parser {
|
|||
|
||||
class Declaration {
|
||||
public:
|
||||
Declaration(DeprecatedFlyString name, Vector<ComponentValue> values, Important);
|
||||
Declaration(FlyString name, Vector<ComponentValue> values, Important);
|
||||
~Declaration();
|
||||
|
||||
StringView name() const { return m_name; }
|
||||
Vector<ComponentValue> const& values() const { return m_values; }
|
||||
Important importance() const { return m_important; }
|
||||
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
|
||||
private:
|
||||
DeprecatedFlyString m_name;
|
||||
FlyString m_name;
|
||||
Vector<ComponentValue> m_values;
|
||||
Important m_important { Important::No };
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1395,7 +1395,7 @@ Optional<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
|
|||
if (auto declaration = consume_a_declaration(block_tokens); declaration.has_value()) {
|
||||
transaction.commit();
|
||||
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
|
||||
// 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<ComponentValue> declaration_values;
|
||||
Important declaration_important = Important::No;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue