diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2022-04-07 17:37:33 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-07 21:20:14 +0200 |
commit | 1f7bf460612449f78465b70d57cebe618580b019 (patch) | |
tree | a08a61008dc0328a6def72c52b92d8de7124a022 /Userland/Libraries | |
parent | 802ccc210f18645ee89bb0341397772e67187900 (diff) | |
download | serenity-1f7bf460612449f78465b70d57cebe618580b019.zip |
LibWeb: Add CSS::UnicodeRange class
This corresponds to `<urange>` in CSS grammar.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/CSS/UnicodeRange.h | 43 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Forward.h | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CSS/UnicodeRange.h b/Userland/Libraries/LibWeb/CSS/UnicodeRange.h new file mode 100644 index 0000000000..74662dda13 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/UnicodeRange.h @@ -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; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 759b585382..94ff7aee15 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -89,6 +89,7 @@ class Time; class TimePercentage; class TimeStyleValue; class TransformationStyleValue; +class UnicodeRange; class UnresolvedStyleValue; class UnsetStyleValue; } |