UnicodeRange.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Assertions.h>
  8. namespace Web::CSS {
  9. // https://www.w3.org/TR/css-syntax-3/#urange-syntax
  10. class UnicodeRange {
  11. public:
  12. UnicodeRange(u32 min_code_point, u32 max_code_point)
  13. : m_min_code_point(min_code_point)
  14. , m_max_code_point(max_code_point)
  15. {
  16. VERIFY(min_code_point <= max_code_point);
  17. }
  18. u32 min_code_point() const { return m_min_code_point; }
  19. u32 max_code_point() const { return m_max_code_point; }
  20. bool contains(u32 code_point) const
  21. {
  22. return m_min_code_point <= code_point && code_point <= m_max_code_point;
  23. }
  24. String to_string() const
  25. {
  26. if (m_min_code_point == m_max_code_point)
  27. return String::formatted("U+{:x}", m_min_code_point);
  28. return String::formatted("U+{:x}-{:x}", m_min_code_point, m_max_code_point);
  29. }
  30. private:
  31. u32 m_min_code_point;
  32. u32 m_max_code_point;
  33. };
  34. }