Declaration.cpp 842 B

123456789101112131415161718192021222324252627282930313233343536
  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/Declaration.h>
  8. #include <LibWeb/CSS/Serialize.h>
  9. namespace Web::CSS::Parser {
  10. Declaration::Declaration(FlyString name, Vector<ComponentValue> values, Important important)
  11. : m_name(move(name))
  12. , m_values(move(values))
  13. , m_important(move(important))
  14. {
  15. }
  16. Declaration::~Declaration() = default;
  17. ErrorOr<String> Declaration::to_string() const
  18. {
  19. StringBuilder builder;
  20. TRY(serialize_an_identifier(builder, m_name));
  21. TRY(builder.try_append(": "sv));
  22. TRY(builder.try_join(' ', m_values));
  23. if (m_important == Important::Yes)
  24. TRY(builder.try_append(" !important"sv));
  25. return builder.to_string();
  26. }
  27. }