summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/Parser/ComponentValue.cpp
blob: cd5463ebd4a2cbcbce35aa3a6068a504b1923f54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright (c) 2020-2021, the SerenityOS developers.
 * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibWeb/CSS/Parser/ComponentValue.h>
#include <LibWeb/CSS/Parser/Function.h>
#include <LibWeb/CSS/Parser/StyleBlockRule.h>

namespace Web::CSS::Parser {

ComponentValue::ComponentValue(Token token)
    : m_value(token)
{
}
ComponentValue::ComponentValue(NonnullRefPtr<Function> function)
    : m_value(function)
{
}
ComponentValue::ComponentValue(NonnullRefPtr<StyleBlockRule> block)
    : m_value(block)
{
}

ComponentValue::~ComponentValue() = default;

String ComponentValue::to_string() const
{
    return m_value.visit(
        [](Token const& token) { return token.to_string(); },
        [](NonnullRefPtr<StyleBlockRule> const& block) { return block->to_string(); },
        [](NonnullRefPtr<Function> 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<StyleBlockRule> const& block) {
            return String::formatted("Function: {}", block->to_string());
        },
        [](NonnullRefPtr<Function> const& function) {
            return String::formatted("Block: {}", function->to_string());
        });
}

}