HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
agrapheme.hpp
1
2
3#pragma once
4
5#include "../unicode/grapheme.hpp"
6#include "../i18n/iso_639.hpp"
7#include "text_phrasing.hpp"
8#include "text_style.hpp"
9#include <bit>
10
11namespace hi::inline v1 {
12
13struct agrapheme {
14 using value_type = uint64_t;
15
23 value_type _value;
24
25 [[nodiscard]] constexpr friend bool operator==(agrapheme const &lhs, agrapheme const &rhs) noexcept = default;
26
27 [[nodiscard]] constexpr friend std::partial_ordering operator<=>(agrapheme const &lhs, agrapheme const &rhs) noexcept
28 {
29 return lhs.grapheme() <=> rhs.grapheme();
30 }
31
32 [[nodiscard]] constexpr bool empty() const noexcept
33 {
34 return grapheme().empty();
35 }
36
37 constexpr explicit operator bool() const noexcept
38 {
39 return not empty();
40 }
41
42 [[nodiscard]] size_t hash() const noexcept
43 {
44 return std::hash<value_type>{}(_value);
45 }
46
47 [[nodiscard]] constexpr hi::grapheme grapheme() const noexcept
48 {
49 return std::bit_cast<hi::grapheme>(truncate<uint32_t>(_value >> 43));
50 }
51
52 [[nodiscard]] constexpr text_phrasing phrasing() const noexcept
53 {
54 return static_cast<text_phrasing>((_value >> 39) & 0xf);
55 }
56
57 [[nodiscard]] constexpr iso_639 language() const noexcept
58 {
59 return std::bit_cast<iso_639>(truncate<uint16_t>(_value >> 16));
60 }
61
62 [[nodiscard]] constexpr text_style style() const noexcept
63 {
64 return std::bit_cast<text_style>(truncate<uint16_t>(_value));
65 }
66
67 [[nodiscard]] text_sub_style sub_style(iso_15924 script = iso_15924{}) const noexcept
68 {
69 return style().sub_style(phrasing(), language(), script);
70 }
71};
72
73}
74
75template<>
76struct std::hash<hi::agrapheme> {
77 [[nodiscard]] size_t operator()(hi::agrapheme const &rhs) const noexcept
78 {
79 return rhs.hash();
80 }
81};
Definition agrapheme.hpp:13
value_type _value
Internal value.
Definition agrapheme.hpp:23
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:41
constexpr bool empty() const noexcept
Check if the grapheme is empty.
Definition grapheme.hpp:120
T operator()(T... args)
Definition datum.hpp:2458