DeclarationOrAtRule.cpp 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2020-2021, the SerenityOS developers.
  3. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibWeb/CSS/Parser/DeclarationOrAtRule.h>
  8. #include <LibWeb/CSS/Parser/Function.h>
  9. namespace Web::CSS::Parser {
  10. DeclarationOrAtRule::DeclarationOrAtRule(RefPtr<Rule> at)
  11. : m_type(DeclarationType::At)
  12. , m_at(move(at))
  13. {
  14. }
  15. DeclarationOrAtRule::DeclarationOrAtRule(Declaration declaration)
  16. : m_type(DeclarationType::Declaration)
  17. , m_declaration(move(declaration))
  18. {
  19. }
  20. DeclarationOrAtRule::~DeclarationOrAtRule() = default;
  21. String DeclarationOrAtRule::to_string() const
  22. {
  23. StringBuilder builder;
  24. switch (m_type) {
  25. default:
  26. case DeclarationType::At:
  27. builder.append(m_at->to_string());
  28. break;
  29. case DeclarationType::Declaration:
  30. builder.append(m_declaration->to_string());
  31. break;
  32. }
  33. return builder.to_string();
  34. }
  35. }