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