summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-02-14 20:03:49 +0000
committerTim Flynn <trflynn89@pm.me>2023-02-15 12:48:26 -0500
commita381ce9519bd1098ed14fe495d830bafe5a3a49b (patch)
tree9a1209a6a94a361cb3ab788b640ae21ee0bfc9a7 /Userland/Libraries/LibWeb/CSS
parentfc3540c4b15be1123239dbe01d1f39a2a6d5a08b (diff)
downloadserenity-a381ce9519bd1098ed14fe495d830bafe5a3a49b.zip
LibWeb: Port CSS::Supports to new Strings
Diffstat (limited to 'Userland/Libraries/LibWeb/CSS')
-rw-r--r--Userland/Libraries/LibWeb/CSS/CSSSupportsRule.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp4
-rw-r--r--Userland/Libraries/LibWeb/CSS/Supports.cpp34
-rw-r--r--Userland/Libraries/LibWeb/CSS/Supports.h22
4 files changed, 32 insertions, 32 deletions
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 <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)
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<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() }
};
}
diff --git a/Userland/Libraries/LibWeb/CSS/Supports.cpp b/Userland/Libraries/LibWeb/CSS/Supports.cpp
index 41287f0b8c..fff9c5d372 100644
--- a/Userland/Libraries/LibWeb/CSS/Supports.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Supports.cpp
@@ -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();
}
}
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 <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()));
}
};