8#include "../strings.hpp"
9#include "../unfair_mutex.hpp"
11#include "../stable_set.hpp"
21namespace hi::inline
v1 {
24inline auto long_graphemes = ::hi::stable_set<std::u32string>{};
42 using value_type = uint32_t;
55 constexpr grapheme() noexcept = default;
61 constexpr
grapheme(nullptr_t) noexcept : _value(0x1f'ffff) {}
65 constexpr explicit grapheme(
char32_t code_point) noexcept : _value(truncate<value_type>(code_point))
70 constexpr explicit grapheme(
char ascii_char) noexcept : _value(truncate<value_type>(ascii_char))
72 hi_axiom(ascii_char >= 0 and ascii_char <= 0x7f);
79 _value = truncate<value_type>(code_point);
87 hi_axiom(ascii_char >= 0 and ascii_char <= 0x7f);
88 _value = truncate<value_type>(ascii_char);
96 explicit grapheme(std::u32string_view code_points)
noexcept;
122 [[nodiscard]]
constexpr bool empty() const noexcept
124 return _value == 0x1f'ffff;
129 constexpr operator bool() const noexcept
141 [[nodiscard]]
bool valid() const noexcept;
143 [[nodiscard]]
std::u32string const& long_grapheme() const noexcept
145 hi_assert(_value >= 0x10'0000 and _value < 0x1f'ffff);
146 return detail::long_graphemes[_value - 0x11'0000];
153 if (_value == 0x1f'ffff) {
156 }
else if (_value <= 0x10'ffff) {
160 return long_grapheme().size();
170 [[nodiscard]]
constexpr char32_t operator[](
size_t i)
const noexcept
172 hi_assert_bounds(i, *
this);
174 if (_value <= 0x10'ffff) {
175 return truncate<char32_t>(_value);
177 return long_grapheme()[i];
189 [[nodiscard]]
friend constexpr char32_t get(
grapheme const& rhs)
noexcept
191 hi_assert_bounds(I, rhs);
193 if (rhs._value <= 0x10'ffff) {
196 return rhs.long_grapheme()[I];
204 if (_value <= 0x10'ffff) {
207 return long_grapheme();
217 [[nodiscard]] friend constexpr
bool operator==(
grapheme const&,
grapheme const&) noexcept = default;
221 [[nodiscard]] friend constexpr
std::strong_ordering operator<=>(
grapheme const& lhs,
grapheme const& rhs) noexcept
223 return lhs.decomposed() <=> rhs.decomposed();
226 [[nodiscard]]
friend constexpr bool operator==(
grapheme const& lhs,
char32_t const& rhs)
noexcept
231 [[nodiscard]]
friend constexpr std::strong_ordering operator<=>(grapheme
const& lhs,
char32_t const& rhs)
noexcept
236 [[nodiscard]]
friend constexpr bool operator==(grapheme
const& lhs,
char const& rhs)
noexcept
241 [[nodiscard]]
friend constexpr std::strong_ordering operator<=>(grapheme
const& lhs,
char const& rhs)
noexcept
253 return rhs.composed();
#define hi_axiom(expression)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
#define hi_assert(expression)
Assert if expression is true.
Definition assert.hpp:86
Utilities used by the HikoGUI library itself.
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
Identity conversion from UTF-32 to UTF-32.
Definition to_string.hpp:23
@ grapheme
The gui_event has grapheme data.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
Definition grapheme.hpp:28
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
std::u32string decomposed() const noexcept
Get a list of code-point normalized to NFD.
constexpr bool empty() const noexcept
Check if the grapheme is empty.
Definition grapheme.hpp:122
bool valid() const noexcept
Check if the grapheme is valid.
constexpr char32_t operator[](size_t i) const noexcept
Get the code-point at the given index.
Definition grapheme.hpp:170
static constexpr grapheme eof() noexcept
Create empty grapheme / end-of-file.
Definition grapheme.hpp:106
grapheme(composed_t, std::u32string_view code_points) noexcept
Encode a grapheme from a list of code-points.
constexpr void clear() noexcept
Clear the grapheme.
Definition grapheme.hpp:115
constexpr grapheme(char32_t code_point) noexcept
Encode a single code-point.
Definition grapheme.hpp:65
constexpr grapheme & operator=(char ascii_char) noexcept
Encode a single code-point.
Definition grapheme.hpp:85
value_type _value
A pointer to a grapheme.
Definition grapheme.hpp:53
grapheme(std::u32string_view code_points) noexcept
Encode a grapheme from a list of code-points.
constexpr std::u32string composed() const noexcept
Get a list of code-point normalized to NFC.
Definition grapheme.hpp:202
constexpr grapheme & operator=(char32_t code_point) noexcept
Encode a single code-point.
Definition grapheme.hpp:77
constexpr std::size_t size() const noexcept
Return the number of code-points encoded in the grapheme.
Definition grapheme.hpp:151
friend constexpr char32_t get(grapheme const &rhs) noexcept
Get the code-point at the given index.
Definition grapheme.hpp:189