HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_15924.hpp
1// Copyright Take Vos 2021-2022.
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 "../utility/module.hpp"
8#include <string_view>
9#include <cstdint>
10#include <format>
11
12namespace hi::inline v1 {
13
17class iso_15924 {
18public:
19 constexpr iso_15924() noexcept : _v(0) {}
20 constexpr iso_15924(iso_15924 const&) noexcept = default;
21 constexpr iso_15924(iso_15924&&) noexcept = default;
22 constexpr iso_15924& operator=(iso_15924 const&) noexcept = default;
23 constexpr iso_15924& operator=(iso_15924&&) noexcept = default;
24
25 constexpr iso_15924(std::integral auto number) : _v(0)
26 {
27 hi_check_bounds(number, 0, 1000);
28 _v = narrow_cast<uint16_t>(number);
29 }
30
31 iso_15924(std::string_view code4);
32
35 [[nodiscard]] constexpr static iso_15924 wildcard() noexcept
36 {
37 return iso_15924{0};
38 }
39
44 [[nodiscard]] constexpr static iso_15924 common() noexcept
45 {
46 return iso_15924{998};
47 }
48
51 [[nodiscard]] constexpr static iso_15924 uncoded() noexcept
52 {
53 return iso_15924{999};
54 }
55
56 [[nodiscard]] constexpr static iso_15924 inherited() noexcept
57 {
58 return iso_15924{994};
59 }
60
61 constexpr iso_15924(intrinsic_t, uint16_t v) noexcept : _v(v)
62 {
63 hi_axiom_bounds(_v, 0, 1000);
64 }
65
66 [[nodiscard]] constexpr uint16_t const& intrinsic() const noexcept
67 {
68 return _v;
69 }
70
71 [[nodiscard]] constexpr uint16_t& intrinsic() noexcept
72 {
73 return _v;
74 }
75
76 [[nodiscard]] constexpr bool empty() const noexcept
77 {
78 return _v == 0;
79 }
80
81 explicit operator bool() const noexcept
82 {
83 return not empty();
84 }
85
88 [[nodiscard]] constexpr uint16_t number() const noexcept
89 {
90 return _v;
91 }
92
95 [[nodiscard]] std::string_view code4() const noexcept;
96
99 [[nodiscard]] std::string_view code4_open_type() const noexcept;
100
103 [[nodiscard]] bool left_to_right() const noexcept;
104
105 [[nodiscard]] constexpr friend bool operator==(iso_15924 const& lhs, iso_15924 const& rhs) noexcept = default;
106 [[nodiscard]] constexpr friend auto operator<=>(iso_15924 const& lhs, iso_15924 const& rhs) noexcept = default;
107
114 [[nodiscard]] constexpr friend bool matches(iso_15924 const& lhs, iso_15924 const& rhs) noexcept
115 {
116 return lhs.empty() or lhs == rhs;
117 }
118
119private:
120 uint16_t _v;
121};
122
123} // namespace hi::inline v1
124
125template<>
126struct std::hash<hi::iso_15924> {
127 [[nodiscard]] size_t operator()(hi::iso_15924 const& rhs) const noexcept
128 {
129 return std::hash<uint16_t>{}(rhs.number());
130 }
131};
#define hi_axiom_bounds(x,...)
Specify an axiom that the value is within bounds.
Definition assert.hpp:264
#define hi_check_bounds(x,...)
Assert if a value is within bounds, or throw a parse_error.
Definition assert.hpp:132
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
ISO-15924 script code.
Definition iso_15924.hpp:17
static constexpr iso_15924 common() noexcept
Common script is used for characters that are common in different scripts.
Definition iso_15924.hpp:44
std::string_view code4() const noexcept
Get the iso-15924 4-letter code.
constexpr uint16_t number() const noexcept
Get the iso-15924 numeric value.
Definition iso_15924.hpp:88
static constexpr iso_15924 uncoded() noexcept
Used when the script was not encoded with the text.
Definition iso_15924.hpp:51
static constexpr iso_15924 wildcard() noexcept
When any script is allowed.
Definition iso_15924.hpp:35
T operator()(T... args)