diff --git a/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp index 7289a0ae30..54acba5ff4 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -32,7 +32,7 @@ JS::ThrowCompletionOr CSSSupportsRule::initialize(JS::Realm& realm) DeprecatedString CSSSupportsRule::condition_text() const { - return m_supports->to_deprecated_string(); + return m_supports->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); } void CSSSupportsRule::set_condition_text(DeprecatedString text) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index d3f852cfa8..9e43248edf 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_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string() } + Supports::Declaration { declaration->to_string().release_value_but_fixme_should_propagate_errors() } }; } } @@ -1408,7 +1408,7 @@ Optional Parser::parse_supports_feature(TokenStream + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -73,45 +73,45 @@ bool Supports::Feature::evaluate() const }); } -DeprecatedString Supports::Declaration::to_deprecated_string() const +ErrorOr Supports::Declaration::to_string() const { - return DeprecatedString::formatted("({})", declaration); + return String::formatted("({})", declaration); } -DeprecatedString Supports::Selector::to_deprecated_string() const +ErrorOr Supports::Selector::to_string() const { - return DeprecatedString::formatted("selector({})", selector); + return String::formatted("selector({})", selector); } -DeprecatedString Supports::Feature::to_deprecated_string() const +ErrorOr Supports::Feature::to_string() const { - return value.visit([](auto& it) { return it.to_deprecated_string(); }); + return value.visit([](auto& it) { return it.to_string(); }); } -DeprecatedString Supports::InParens::to_deprecated_string() const +ErrorOr Supports::InParens::to_string() const { return value.visit( - [](NonnullOwnPtr const& condition) -> DeprecatedString { return DeprecatedString::formatted("({})", condition->to_deprecated_string()); }, - [](Supports::Feature const& it) -> DeprecatedString { return it.to_deprecated_string(); }, - [](GeneralEnclosed const& it) -> DeprecatedString { return it.to_string(); }); + [](NonnullOwnPtr const& condition) -> ErrorOr { return String::formatted("({})", TRY(condition->to_string())); }, + [](Supports::Feature const& it) -> ErrorOr { return it.to_string(); }, + [](GeneralEnclosed const& it) -> ErrorOr { return String::from_utf8(it.to_string()); }); } -DeprecatedString Supports::Condition::to_deprecated_string() const +ErrorOr Supports::Condition::to_string() const { switch (type) { case Type::Not: - return DeprecatedString::formatted("not {}", children.first().to_deprecated_string()); + return String::formatted("not {}", TRY(children.first().to_string())); case Type::And: - return DeprecatedString::join(" and "sv, children); + return String::join(" and "sv, children); case Type::Or: - return DeprecatedString::join(" or "sv, children); + return String::join(" or "sv, children); } VERIFY_NOT_REACHED(); } -DeprecatedString Supports::to_deprecated_string() const +ErrorOr Supports::to_string() const { - return m_condition->to_deprecated_string(); + return m_condition->to_string(); } } diff --git a/Userland/Libraries/LibWeb/CSS/Supports.h b/Userland/Libraries/LibWeb/CSS/Supports.h index 385fc5eb7f..99f8f01afc 100644 --- a/Userland/Libraries/LibWeb/CSS/Supports.h +++ b/Userland/Libraries/LibWeb/CSS/Supports.h @@ -1,14 +1,14 @@ /* - * Copyright (c) 2021-2022, Sam Atkins + * Copyright (c) 2021-2023, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once -#include #include #include +#include #include #include #include @@ -22,21 +22,21 @@ class Supports final : public RefCounted { public: struct Declaration { - DeprecatedString declaration; + String declaration; bool evaluate() const; - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; }; struct Selector { - DeprecatedString selector; + String selector; bool evaluate() const; - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; }; struct Feature { Variant value; bool evaluate() const; - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; }; struct Condition; @@ -44,7 +44,7 @@ public: Variant, Feature, GeneralEnclosed> value; bool evaluate() const; - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; }; struct Condition { @@ -57,7 +57,7 @@ public: Vector children; bool evaluate() const; - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; }; static NonnullRefPtr create(NonnullOwnPtr&& condition) @@ -66,7 +66,7 @@ public: } bool matches() const { return m_matches; } - DeprecatedString to_deprecated_string() const; + ErrorOr to_string() const; private: Supports(NonnullOwnPtr&&); @@ -81,6 +81,6 @@ template<> struct AK::Formatter : AK::Formatter { ErrorOr format(FormatBuilder& builder, Web::CSS::Supports::InParens const& in_parens) { - return Formatter::format(builder, in_parens.to_deprecated_string()); + return Formatter::format(builder, TRY(in_parens.to_string())); } };