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