7#include "ucd_grapheme_cluster_breaks.hpp"
8#include "unicode_break_opportunity.hpp"
9#include "../macros.hpp"
13hi_export_module(hikogui.unicode.unicode_grapheme_cluster_break);
15hi_export
namespace hi {
inline namespace v1 {
19 unicode_grapheme_cluster_break previous = unicode_grapheme_cluster_break::Other;
21 bool first_character =
true;
22 bool in_extended_pictograph =
false;
24 constexpr void reset()
noexcept
26 previous = unicode_grapheme_cluster_break::Other;
28 first_character =
true;
29 in_extended_pictograph =
false;
41[[nodiscard]]
constexpr bool breaks_grapheme(unicode_grapheme_cluster_break cluster_break,
grapheme_break_state& state)
noexcept
43 using enum unicode_grapheme_cluster_break;
45 auto const lhs = state.previous;
46 auto const rhs = cluster_break;
48 enum class break_state {
54 break_state break_state = break_state::unknown;
57 bool GB1 = state.first_character;
58 if ((break_state == break_state::unknown) & GB1) {
59 break_state = break_state::do_break;
62 state.first_character =
false;
65 auto const GB3 = (lhs == CR) && (rhs == LF);
66 auto const GB4 = (lhs == Control) || (lhs == CR) || (lhs == LF);
67 auto const GB5 = (rhs == Control) || (rhs == CR) || (rhs == LF);
68 if (break_state == break_state::unknown) {
70 break_state = break_state::dont_break;
71 }
else if (GB4 || GB5) {
72 break_state = break_state::do_break;
77 auto const GB6 = (lhs == L) && ((rhs == L) || (rhs == V) || (rhs == LV) | (rhs == LVT));
78 auto const GB7 = ((lhs == LV) || (lhs == V)) && ((rhs == V) || (rhs == T));
79 auto const GB8 = ((lhs == LVT) || (lhs == T)) && (rhs == T);
80 if ((break_state == break_state::unknown) && (GB6 || GB7 || GB8)) {
81 break_state = break_state::dont_break;
85 auto const GB9 = ((rhs == Extend) || (rhs == ZWJ));
89 auto const GB9a = (rhs == SpacingMark);
90 auto const GB9b = (lhs == Prepend);
91 if ((break_state == break_state::unknown) & (GB9 || GB9a || GB9b)) {
92 break_state = break_state::dont_break;
96 auto const GB11 = state.in_extended_pictograph && (lhs == ZWJ) && (rhs == Extended_Pictographic);
97 if ((break_state == break_state::unknown) && GB11) {
98 break_state = break_state::dont_break;
101 if (rhs == Extended_Pictographic) {
102 state.in_extended_pictograph =
true;
103 }
else if (!((rhs == Extend) || (rhs == ZWJ))) {
104 state.in_extended_pictograph =
false;
110 auto const GB12_13 = (lhs == Regional_Indicator) && (rhs == Regional_Indicator) && ((state.RI_count % 2) == 1);
111 if ((break_state == break_state::unknown) && (GB12_13)) {
112 break_state = break_state::dont_break;
115 if (rhs == Regional_Indicator) {
122 if (break_state == break_state::unknown) {
123 break_state = break_state::do_break;
126 state.previous = rhs;
127 return break_state == break_state::do_break;
137[[nodiscard]]
constexpr bool breaks_grapheme(
char32_t code_point, grapheme_break_state& state)
noexcept
139 return breaks_grapheme(ucd_get_grapheme_cluster_break(code_point), state);
144template<
typename It,
typename ItEnd>
148 auto state = detail::grapheme_break_state{};
150 for (
auto it = first; it != last; ++it) {
151 auto const opportunity = detail::breaks_grapheme(*it, state) ? unicode_break_opportunity::yes : unicode_break_opportunity::no;
155 r.push_back(unicode_break_opportunity::yes);
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition unicode_grapheme_cluster_break.hpp:18