mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibWeb: Port CSS::Supports to new Strings
This commit is contained in:
parent
fc3540c4b1
commit
a381ce9519
Notes:
sideshowbarker
2024-07-17 03:05:16 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/a381ce9519 Pull-request: https://github.com/SerenityOS/serenity/pull/17478 Reviewed-by: https://github.com/trflynn89 ✅
@ -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
|
||||
*/
|
||||
@ -32,7 +32,7 @@ JS::ThrowCompletionOr<void> 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)
|
||||
|
@ -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_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());
|
||||
transaction.commit();
|
||||
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
|
||||
*/
|
||||
@ -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(
|
||||
[](NonnullOwnPtr<Condition> 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<Condition> const& condition) -> ErrorOr<String> { return String::formatted("({})", TRY(condition->to_string())); },
|
||||
[](Supports::Feature const& it) -> ErrorOr<String> { 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) {
|
||||
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<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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/GeneralEnclosed.h>
|
||||
@ -22,21 +22,21 @@ class Supports final : public RefCounted<Supports> {
|
||||
|
||||
public:
|
||||
struct Declaration {
|
||||
DeprecatedString declaration;
|
||||
String declaration;
|
||||
bool evaluate() const;
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
};
|
||||
|
||||
struct Selector {
|
||||
DeprecatedString selector;
|
||||
String selector;
|
||||
bool evaluate() const;
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
};
|
||||
|
||||
struct Feature {
|
||||
Variant<Declaration, Selector> value;
|
||||
bool evaluate() const;
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
};
|
||||
|
||||
struct Condition;
|
||||
@ -44,7 +44,7 @@ public:
|
||||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||
|
||||
bool evaluate() const;
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
};
|
||||
|
||||
struct Condition {
|
||||
@ -57,7 +57,7 @@ public:
|
||||
Vector<InParens> children;
|
||||
|
||||
bool evaluate() const;
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
||||
@ -66,7 +66,7 @@ public:
|
||||
}
|
||||
|
||||
bool matches() const { return m_matches; }
|
||||
DeprecatedString to_deprecated_string() const;
|
||||
ErrorOr<String> to_string() const;
|
||||
|
||||
private:
|
||||
Supports(NonnullOwnPtr<Condition>&&);
|
||||
@ -81,6 +81,6 @@ template<>
|
||||
struct AK::Formatter<Web::CSS::Supports::InParens> : AK::Formatter<StringView> {
|
||||
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…
Reference in New Issue
Block a user