1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibWeb: Port CSS::Parser::Function to new Strings

This commit is contained in:
Sam Atkins 2023-02-14 18:55:59 +00:00 committed by Tim Flynn
parent 86d23c63a4
commit 05c1b09621
5 changed files with 20 additions and 19 deletions

View file

@ -31,7 +31,7 @@ DeprecatedString ComponentValue::to_deprecated_string() const
return m_value.visit(
[](Token const& token) { return token.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); },
[](NonnullRefPtr<Block> const& block) { return block->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); },
[](NonnullRefPtr<Function> const& function) { return function->to_deprecated_string(); });
[](NonnullRefPtr<Function> const& function) { return function->to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string(); });
}
ErrorOr<String> ComponentValue::to_debug_string() const
@ -44,7 +44,7 @@ ErrorOr<String> ComponentValue::to_debug_string() const
return String::formatted("Block: {}", TRY(block->to_string()));
},
[](NonnullRefPtr<Function> const& function) -> ErrorOr<String> {
return String::formatted("Function: {}", function->to_deprecated_string());
return String::formatted("Function: {}", TRY(function->to_string()));
});
}

View file

@ -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 {
Function::Function(DeprecatedFlyString name, Vector<ComponentValue>&& values)
Function::Function(FlyString name, Vector<ComponentValue>&& values)
: m_name(move(name))
, m_values(move(values))
{
@ -18,16 +18,16 @@ Function::Function(DeprecatedFlyString name, Vector<ComponentValue>&& values)
Function::~Function() = default;
DeprecatedString Function::to_deprecated_string() const
ErrorOr<String> Function::to_string() const
{
StringBuilder builder;
serialize_an_identifier(builder, m_name);
builder.append('(');
builder.join(' ', m_values);
builder.append(')');
TRY(builder.try_append('('));
TRY(builder.try_join(' ', m_values));
TRY(builder.try_append(')'));
return builder.to_deprecated_string();
return builder.to_string();
}
}

View file

@ -1,15 +1,15 @@
/*
* 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
*/
#pragma once
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/FlyString.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibWeb/CSS/Parser/ComponentValue.h>
#include <LibWeb/Forward.h>
@ -18,7 +18,7 @@ namespace Web::CSS::Parser {
class Function : public RefCounted<Function> {
public:
static NonnullRefPtr<Function> create(DeprecatedFlyString name, Vector<ComponentValue>&& values)
static NonnullRefPtr<Function> create(FlyString name, Vector<ComponentValue>&& values)
{
return adopt_ref(*new Function(move(name), move(values)));
}
@ -28,12 +28,12 @@ public:
StringView name() const { return m_name; }
Vector<ComponentValue> const& values() const { return m_values; }
DeprecatedString to_deprecated_string() const;
ErrorOr<String> to_string() const;
private:
Function(DeprecatedFlyString name, Vector<ComponentValue>&& values);
Function(FlyString name, Vector<ComponentValue>&& values);
DeprecatedFlyString m_name;
FlyString m_name;
Vector<ComponentValue> m_values;
};
}

View file

@ -1801,7 +1801,7 @@ NonnullRefPtr<Function> Parser::consume_a_function(TokenStream<T>& tokens)
// Create a function with its name equal to the value of the current input token
// and with its value initially set to an empty list.
// NOTE: We create the Function fully initialized when we return it instead.
DeprecatedFlyString function_name = ((Token)name_ident).function();
auto function_name = FlyString::from_utf8(((Token)name_ident).function()).release_value_but_fixme_should_propagate_errors();
Vector<ComponentValue> function_values;
// Repeatedly consume the next input token and process it as follows:

View file

@ -628,7 +628,7 @@ bool StyleComputer::expand_variables(DOM::Element& element, StringView property_
Parser::TokenStream source_function_contents { source_function.values() };
if (!expand_variables(element, property_name, dependencies, source_function_contents, function_values))
return false;
NonnullRefPtr<Parser::Function> function = Parser::Function::create(source_function.name(), move(function_values));
NonnullRefPtr<Parser::Function> function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values));
dest.empend(function);
continue;
}
@ -750,7 +750,8 @@ bool StyleComputer::expand_unresolved_values(DOM::Element& element, StringView p
Parser::TokenStream source_function_contents { source_function.values() };
if (!expand_unresolved_values(element, property_name, source_function_contents, function_values))
return false;
NonnullRefPtr<Parser::Function> function = Parser::Function::create(source_function.name(), move(function_values));
// FIXME: This would be much nicer if we could access the source_function's FlyString value directly.
NonnullRefPtr<Parser::Function> function = Parser::Function::create(FlyString::from_utf8(source_function.name()).release_value_but_fixme_should_propagate_errors(), move(function_values));
dest.empend(function);
continue;
}