ComponentValue.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/CSS/Parser/ComponentValue.h>
  8. namespace Web::CSS::Parser {
  9. ComponentValue::ComponentValue(Token token)
  10. : m_value(token)
  11. {
  12. }
  13. ComponentValue::ComponentValue(Function&& function)
  14. : m_value(function)
  15. {
  16. }
  17. ComponentValue::ComponentValue(SimpleBlock&& block)
  18. : m_value(block)
  19. {
  20. }
  21. ComponentValue::~ComponentValue() = default;
  22. bool ComponentValue::is_function(StringView name) const
  23. {
  24. return is_function() && function().name.equals_ignoring_ascii_case(name);
  25. }
  26. bool ComponentValue::is_ident(StringView ident) const
  27. {
  28. return is(Token::Type::Ident) && token().ident().equals_ignoring_ascii_case(ident);
  29. }
  30. String ComponentValue::to_string() const
  31. {
  32. return m_value.visit(
  33. [](Token const& token) { return token.to_string(); },
  34. [](SimpleBlock const& block) { return block.to_string(); },
  35. [](Function const& function) { return function.to_string(); });
  36. }
  37. String ComponentValue::to_debug_string() const
  38. {
  39. return m_value.visit(
  40. [](Token const& token) {
  41. return MUST(String::formatted("Token: {}", token.to_debug_string()));
  42. },
  43. [](SimpleBlock const& block) {
  44. return MUST(String::formatted("Block: {}", block.to_string()));
  45. },
  46. [](Function const& function) {
  47. return MUST(String::formatted("Function: {}", function.to_string()));
  48. });
  49. }
  50. }