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 hi::inline v1 {
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 bool is_control(unicode_bidi_class const &rhs) noexcept
64{
65 using enum unicode_bidi_class;
66 return rhs == RLE or rhs == LRE or rhs == RLO or rhs == LRO or rhs == PDF or rhs == BN;
67}
68
69[[nodiscard]] constexpr unicode_bidi_class unicode_bidi_class_from_string(std::string_view str) noexcept
70{
71 using enum unicode_bidi_class;
72
73 if (str == "L") {
74 return L;
75 } else if (str == "R") {
76 return R;
77 } else if (str == "AL") {
78 return AL;
79 } else if (str == "EN") {
80 return EN;
81 } else if (str == "ES") {
82 return ES;
83 } else if (str == "ET") {
84 return ET;
85 } else if (str == "AN") {
86 return AN;
87 } else if (str == "CS") {
88 return CS;
89 } else if (str == "NSM") {
90 return NSM;
91 } else if (str == "BN") {
92 return BN;
93 } else if (str == "B") {
94 return B;
95 } else if (str == "S") {
96 return S;
97 } else if (str == "WS") {
98 return WS;
99 } else if (str == "ON") {
100 return ON;
101 } else if (str == "LRE") {
102 return LRE;
103 } else if (str == "LRO") {
104 return LRO;
105 } else if (str == "RLE") {
106 return RLE;
107 } else if (str == "RLO") {
108 return RLO;
109 } else if (str == "PDF") {
110 return PDF;
111 } else if (str == "LRI") {
112 return LRI;
113 } else if (str == "RLI") {
114 return RLI;
115 } else if (str == "FSI") {
116 return FSI;
117 } else if (str == "PDI") {
118 return PDI;
119 } else {
120 hi_no_default();
121 }
122}
123
124} // namespace hi::inline v1