mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
LibWeb: Port CSS::Supports to new Strings
This commit is contained in:
parent
fc3540c4b1
commit
a381ce9519
4 changed files with 32 additions and 32 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021, 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
|
||||||
*/
|
*/
|
||||||
|
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<void> CSSSupportsRule::initialize(JS::Realm& realm)
|
||||||
|
|
||||||
DeprecatedString CSSSupportsRule::condition_text() const
|
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)
|
void CSSSupportsRule::set_condition_text(DeprecatedString text)
|
||||||
|
|
|
@ -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_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<Supports::Feature> Parser::parse_supports_feature(TokenStream<Component
|
||||||
builder.append(item.to_string().release_value_but_fixme_should_propagate_errors());
|
builder.append(item.to_string().release_value_but_fixme_should_propagate_errors());
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
return Supports::Feature {
|
return Supports::Feature {
|
||||||
Supports::Selector { builder.to_deprecated_string() }
|
Supports::Selector { builder.to_string().release_value_but_fixme_should_propagate_errors() }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
@ -73,45 +73,45 @@ bool Supports::Feature::evaluate() const
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Supports::Declaration::to_deprecated_string() const
|
ErrorOr<String> Supports::Declaration::to_string() const
|
||||||
{
|
{
|
||||||
return DeprecatedString::formatted("({})", declaration);
|
return String::formatted("({})", declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Supports::Selector::to_deprecated_string() const
|
ErrorOr<String> Supports::Selector::to_string() const
|
||||||
{
|
{
|
||||||
return DeprecatedString::formatted("selector({})", selector);
|
return String::formatted("selector({})", selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Supports::Feature::to_deprecated_string() const
|
ErrorOr<String> 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<String> Supports::InParens::to_string() const
|
||||||
{
|
{
|
||||||
return value.visit(
|
return value.visit(
|
||||||
[](NonnullOwnPtr<Condition> const& condition) -> DeprecatedString { return DeprecatedString::formatted("({})", condition->to_deprecated_string()); },
|
[](NonnullOwnPtr<Condition> const& condition) -> ErrorOr<String> { return String::formatted("({})", TRY(condition->to_string())); },
|
||||||
[](Supports::Feature const& it) -> DeprecatedString { return it.to_deprecated_string(); },
|
[](Supports::Feature const& it) -> ErrorOr<String> { return it.to_string(); },
|
||||||
[](GeneralEnclosed const& it) -> DeprecatedString { return it.to_string(); });
|
[](GeneralEnclosed const& it) -> ErrorOr<String> { return String::from_utf8(it.to_string()); });
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Supports::Condition::to_deprecated_string() const
|
ErrorOr<String> Supports::Condition::to_string() const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::Not:
|
case Type::Not:
|
||||||
return DeprecatedString::formatted("not {}", children.first().to_deprecated_string());
|
return String::formatted("not {}", TRY(children.first().to_string()));
|
||||||
case Type::And:
|
case Type::And:
|
||||||
return DeprecatedString::join(" and "sv, children);
|
return String::join(" and "sv, children);
|
||||||
case Type::Or:
|
case Type::Or:
|
||||||
return DeprecatedString::join(" or "sv, children);
|
return String::join(" or "sv, children);
|
||||||
}
|
}
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
DeprecatedString Supports::to_deprecated_string() const
|
ErrorOr<String> Supports::to_string() const
|
||||||
{
|
{
|
||||||
return m_condition->to_deprecated_string();
|
return m_condition->to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
/*
|
/*
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/DeprecatedString.h>
|
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/Variant.h>
|
#include <AK/Variant.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <LibWeb/CSS/GeneralEnclosed.h>
|
#include <LibWeb/CSS/GeneralEnclosed.h>
|
||||||
|
@ -22,21 +22,21 @@ class Supports final : public RefCounted<Supports> {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Declaration {
|
struct Declaration {
|
||||||
DeprecatedString declaration;
|
String declaration;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Selector {
|
struct Selector {
|
||||||
DeprecatedString selector;
|
String selector;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Feature {
|
struct Feature {
|
||||||
Variant<Declaration, Selector> value;
|
Variant<Declaration, Selector> value;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition;
|
struct Condition;
|
||||||
|
@ -44,7 +44,7 @@ public:
|
||||||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||||
|
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition {
|
struct Condition {
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
Vector<InParens> children;
|
Vector<InParens> children;
|
||||||
|
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
DeprecatedString to_deprecated_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matches() const { return m_matches; }
|
bool matches() const { return m_matches; }
|
||||||
DeprecatedString to_deprecated_string() const;
|
ErrorOr<String> to_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Supports(NonnullOwnPtr<Condition>&&);
|
Supports(NonnullOwnPtr<Condition>&&);
|
||||||
|
@ -81,6 +81,6 @@ template<>
|
||||||
struct AK::Formatter<Web::CSS::Supports::InParens> : AK::Formatter<StringView> {
|
struct AK::Formatter<Web::CSS::Supports::InParens> : AK::Formatter<StringView> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Supports::InParens const& in_parens)
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Supports::InParens const& in_parens)
|
||||||
{
|
{
|
||||||
return Formatter<StringView>::format(builder, in_parens.to_deprecated_string());
|
return Formatter<StringView>::format(builder, TRY(in_parens.to_string()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue