1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 00:47:36 +00:00

LibWeb: Add CSS::UnicodeRange class

This corresponds to `<urange>` in CSS grammar.
This commit is contained in:
Sam Atkins 2022-04-07 17:37:33 +01:00 committed by Andreas Kling
parent 802ccc210f
commit 1f7bf46061
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Assertions.h>
namespace Web::CSS {
// https://www.w3.org/TR/css-syntax-3/#urange-syntax
class UnicodeRange {
public:
UnicodeRange(u32 min_code_point, u32 max_code_point)
: m_min_code_point(min_code_point)
, m_max_code_point(max_code_point)
{
VERIFY(min_code_point <= max_code_point);
}
u32 min_code_point() const { return m_min_code_point; }
u32 max_code_point() const { return m_max_code_point; }
bool contains(u32 code_point) const
{
return m_min_code_point <= code_point && code_point <= m_max_code_point;
}
String to_string() const
{
if (m_min_code_point == m_max_code_point)
return String::formatted("U+{:x}", m_min_code_point);
return String::formatted("U+{:x}-{:x}", m_min_code_point, m_max_code_point);
}
private:
u32 m_min_code_point;
u32 m_max_code_point;
};
}