UnicodeRange.h 1.0 KB

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