From b7453eafbb92f68afaa32c3a92edf5194f79ba3f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 12 Apr 2022 11:14:12 +0100 Subject: LibWeb: Move ComponentValue code into ComponentValue.cpp --- .../Libraries/LibWeb/CSS/Parser/ComponentValue.cpp | 51 ++++++++++++++++++++++ .../Libraries/LibWeb/CSS/Parser/StyleRules.cpp | 36 --------------- 2 files changed, 51 insertions(+), 36 deletions(-) create mode 100644 Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp (limited to 'Userland/Libraries/LibWeb/CSS') diff --git a/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp new file mode 100644 index 0000000000..bc5fbf2644 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020-2021, the SerenityOS developers. + * Copyright (c) 2021-2022, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::CSS { + +ComponentValue::ComponentValue(Token token) + : m_value(token) +{ +} +ComponentValue::ComponentValue(NonnullRefPtr function) + : m_value(function) +{ +} +ComponentValue::ComponentValue(NonnullRefPtr block) + : m_value(block) +{ +} + +ComponentValue::~ComponentValue() = default; + +String ComponentValue::to_string() const +{ + return m_value.visit( + [](Token const& token) { return token.to_string(); }, + [](NonnullRefPtr const& block) { return block->to_string(); }, + [](NonnullRefPtr const& function) { return function->to_string(); }); +} + +String ComponentValue::to_debug_string() const +{ + return m_value.visit( + [](Token const& token) { + return String::formatted("Token: {}", token.to_debug_string()); + }, + [](NonnullRefPtr const& block) { + return String::formatted("Function: {}", block->to_string()); + }, + [](NonnullRefPtr const& function) { + return String::formatted("Block: {}", function->to_string()); + }); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp index fdbb112c5b..460f3dec00 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/StyleRules.cpp @@ -36,20 +36,6 @@ StyleRule::~StyleRule() = default; StyleBlockRule::StyleBlockRule() = default; StyleBlockRule::~StyleBlockRule() = default; -ComponentValue::ComponentValue(Token token) - : m_value(token) -{ -} -ComponentValue::ComponentValue(NonnullRefPtr function) - : m_value(function) -{ -} -ComponentValue::ComponentValue(NonnullRefPtr block) - : m_value(block) -{ -} -ComponentValue::~ComponentValue() = default; - Declaration::Declaration() = default; Declaration::~Declaration() = default; @@ -124,28 +110,6 @@ String StyleBlockRule::to_string() const return builder.to_string(); } -String ComponentValue::to_string() const -{ - return m_value.visit( - [](Token const& token) { return token.to_string(); }, - [](NonnullRefPtr const& block) { return block->to_string(); }, - [](NonnullRefPtr const& function) { return function->to_string(); }); -} - -String ComponentValue::to_debug_string() const -{ - return m_value.visit( - [](Token const& token) { - return String::formatted("Token: {}", token.to_debug_string()); - }, - [](NonnullRefPtr const& block) { - return String::formatted("Function: {}", block->to_string()); - }, - [](NonnullRefPtr const& function) { - return String::formatted("Block: {}", function->to_string()); - }); -} - String Declaration::to_string() const { StringBuilder builder; -- cgit v1.2.3