7#include "../utility/module.hpp"
8#include "../strings.hpp"
9#include "../stable_set.hpp"
19namespace hi::inline
v1 {
22inline auto long_graphemes = ::hi::stable_set<std::u32string>{};
40 using value_type = uint32_t;
53 constexpr grapheme() noexcept = default;
59 constexpr
grapheme(nullptr_t) noexcept : _value(0x1f'ffff) {}
63 constexpr explicit grapheme(
char32_t code_point) noexcept : _value(truncate<value_type>(code_point))
68 constexpr explicit grapheme(
char ascii_char) noexcept : _value(truncate<value_type>(ascii_char))
70 hi_axiom(ascii_char >= 0 and ascii_char <= 0x7f);
77 _value = truncate<value_type>(code_point);
85 hi_axiom(ascii_char >= 0 and ascii_char <= 0x7f);
86 _value = truncate<value_type>(ascii_char);
94 explicit grapheme(std::u32string_view code_points)
noexcept;
120 [[nodiscard]]
constexpr bool empty() const noexcept
122 return _value == 0x1f'ffff;
127 constexpr operator bool() const noexcept
139 [[nodiscard]]
bool valid() const noexcept;
141 [[nodiscard]]
std::u32string const& long_grapheme() const noexcept
143 hi_assert(_value >= 0x10'0000 and _value < 0x1f'ffff);
144 return detail::long_graphemes[_value - 0x11'0000];
151 if (_value == 0x1f'ffff) {
154 }
else if (_value <= 0x10'ffff) {
158 return long_grapheme().size();
168 [[nodiscard]]
constexpr char32_t operator[](
size_t i)
const noexcept
172 if (_value <= 0x10'ffff) {
173 return truncate<char32_t>(_value);
175 return long_grapheme()[i];
187 [[nodiscard]]
friend constexpr char32_t get(
grapheme const& rhs)
noexcept
191 if (rhs._value <= 0x10'ffff) {
194 return rhs.long_grapheme()[I];
202 if (_value <= 0x10'ffff) {
205 return long_grapheme();
215 [[nodiscard]] friend constexpr
bool operator==(
grapheme const&,
grapheme const&) noexcept = default;
219 [[nodiscard]] friend constexpr
std::strong_ordering operator<=>(
grapheme const& lhs,
grapheme const& rhs) noexcept
221 return lhs.decomposed() <=> rhs.decomposed();
224 [[nodiscard]]
friend constexpr bool operator==(
grapheme const& lhs,
char32_t const& rhs)
noexcept
229 [[nodiscard]]
friend constexpr std::strong_ordering operator<=>(grapheme
const& lhs,
char32_t const& rhs)
noexcept
234 [[nodiscard]]
friend constexpr bool operator==(grapheme
const& lhs,
char const& rhs)
noexcept
239 [[nodiscard]]
friend constexpr std::strong_ordering operator<=>(grapheme
const& lhs,
char const& rhs)
noexcept
251 return rhs.composed();
#define hi_assert_bounds(x,...)
Assert if a value is within bounds.
Definition assert.hpp:210
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:184
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
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:13
geometry/margins.hpp
Definition cache.hpp:11
Definition grapheme.hpp:26
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:39
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:120
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:168
static constexpr grapheme eof() noexcept
Create empty grapheme / end-of-file.
Definition grapheme.hpp:104
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:113
constexpr grapheme(char32_t code_point) noexcept
Encode a single code-point.
Definition grapheme.hpp:63
constexpr grapheme & operator=(char ascii_char) noexcept
Encode a single code-point.
Definition grapheme.hpp:83
value_type _value
A pointer to a grapheme.
Definition grapheme.hpp:51
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:200
constexpr grapheme & operator=(char32_t code_point) noexcept
Encode a single code-point.
Definition grapheme.hpp:75
constexpr std::size_t size() const noexcept
Return the number of code-points encoded in the grapheme.
Definition grapheme.hpp:149
friend constexpr char32_t get(grapheme const &rhs) noexcept
Get the code-point at the given index.
Definition grapheme.hpp:187