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