HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
unicode_bidi_class.hpp
1// Copyright Take Vos 2020.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <cstdint>
8
9namespace tt {
10
14enum class unicode_bidi_class : uint8_t {
15 unknown = 0,
16 L = 1,
17 R = 2,
18 AL = 3,
19 EN = 4,
20 ES = 5,
21 ET = 6,
22 AN = 7,
23 CS = 8,
24 NSM = 9,
25 BN = 10,
26 B = 11,
27 S = 12,
28 WS = 13,
29 ON = 14,
30 // Explicit values.
31 LRE,
32 LRO,
33 RLE,
34 RLO,
35 PDF,
36 LRI,
37 RLI,
38 FSI,
39 PDI
40};
41
42[[nodiscard]] constexpr bool is_isolate_starter(unicode_bidi_class const &rhs) noexcept
43{
44 using enum unicode_bidi_class;
45 return rhs == LRI || rhs == RLI || rhs == FSI;
46}
47
48[[nodiscard]] constexpr bool is_isolate_formatter(unicode_bidi_class const &rhs) noexcept
49{
50 using enum unicode_bidi_class;
51 return is_isolate_starter(rhs) || rhs == PDI;
52}
53
54[[nodiscard]] constexpr bool is_NI(unicode_bidi_class const &rhs) noexcept
55{
56 using enum unicode_bidi_class;
57 return rhs == B || rhs == S || rhs == WS || rhs == ON || rhs == FSI || rhs == LRI || rhs == RLI || rhs == PDI;
58}
59
60[[nodiscard]] constexpr unicode_bidi_class unicode_bidi_class_from_string(std::string_view str) noexcept
61{
62 using enum unicode_bidi_class;
63
64 if (str == "L") {
65 return L;
66 } else if (str == "R") {
67 return R;
68 } else if (str == "AL") {
69 return AL;
70 } else if (str == "EN") {
71 return EN;
72 } else if (str == "ES") {
73 return ES;
74 } else if (str == "ET") {
75 return ET;
76 } else if (str == "AN") {
77 return AN;
78 } else if (str == "CS") {
79 return CS;
80 } else if (str == "NSM") {
81 return NSM;
82 } else if (str == "BN") {
83 return BN;
84 } else if (str == "B") {
85 return B;
86 } else if (str == "S") {
87 return S;
88 } else if (str == "WS") {
89 return WS;
90 } else if (str == "ON") {
91 return ON;
92 } else if (str == "LRE") {
93 return LRE;
94 } else if (str == "LRO") {
95 return LRO;
96 } else if (str == "RLE") {
97 return RLE;
98 } else if (str == "RLO") {
99 return RLO;
100 } else if (str == "PDF") {
101 return PDF;
102 } else if (str == "LRI") {
103 return LRI;
104 } else if (str == "RLI") {
105 return RLI;
106 } else if (str == "FSI") {
107 return FSI;
108 } else if (str == "PDI") {
109 return PDI;
110 } else {
111 tt_no_default();
112 }
113}
114
115} // namespace tt