ComponentValue.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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([](auto const& it) { return it.to_string(); });
  33. }
  34. String ComponentValue::to_debug_string() const
  35. {
  36. return m_value.visit(
  37. [](Token const& token) {
  38. return MUST(String::formatted("Token: {}", token.to_debug_string()));
  39. },
  40. [](SimpleBlock const& block) {
  41. return MUST(String::formatted("Block: {}", block.to_string()));
  42. },
  43. [](Function const& function) {
  44. return MUST(String::formatted("Function: {}", function.to_string()));
  45. });
  46. }
  47. String ComponentValue::original_source_text() const
  48. {
  49. return m_value.visit([](auto const& it) { return it.original_source_text(); });
  50. }
  51. }