HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_15924_intf.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/utility.hpp"
8#include "../macros.hpp"
9#include <string_view>
10#include <cstdint>
11#include <format>
12#include <compare>
13#include <string>
14#include <string_view>
15
16hi_export_module(hikogui.i18n.iso_15924 : intf);
17
18hi_export namespace hi { inline namespace v1 {
19
23class iso_15924 {
24public:
25 constexpr iso_15924() noexcept : _v(0) {}
26 constexpr iso_15924(iso_15924 const&) noexcept = default;
27 constexpr iso_15924(iso_15924&&) noexcept = default;
28 constexpr iso_15924& operator=(iso_15924 const&) noexcept = default;
29 constexpr iso_15924& operator=(iso_15924&&) noexcept = default;
30
31 constexpr iso_15924(std::integral auto number) : _v(0)
32 {
33 hi_check_bounds(number, 0, 1000);
34 _v = narrow_cast<uint16_t>(number);
35 }
36
37 constexpr iso_15924(std::string_view code4);
38
41 [[nodiscard]] constexpr static iso_15924 wildcard() noexcept
42 {
43 return iso_15924{0};
44 }
45
50 [[nodiscard]] constexpr static iso_15924 common() noexcept
51 {
52 return iso_15924{998};
53 }
54
57 [[nodiscard]] constexpr static iso_15924 uncoded() noexcept
58 {
59 return iso_15924{999};
60 }
61
62 [[nodiscard]] constexpr static iso_15924 inherited() noexcept
63 {
64 return iso_15924{994};
65 }
66
67 constexpr iso_15924(std::in_place_t, uint16_t v) noexcept : _v(v)
68 {
69 hi_axiom_bounds(_v, 0, 1000);
70 }
71
72 [[nodiscard]] constexpr uint16_t const& intrinsic() const noexcept
73 {
74 return _v;
75 }
76
77 [[nodiscard]] constexpr uint16_t& intrinsic() noexcept
78 {
79 return _v;
80 }
81
82 [[nodiscard]] constexpr bool empty() const noexcept
83 {
84 return _v == 0;
85 }
86
87 constexpr explicit operator bool() const noexcept
88 {
89 return not empty();
90 }
91
94 [[nodiscard]] constexpr uint16_t number() const noexcept
95 {
96 return _v;
97 }
98
101 [[nodiscard]] constexpr std::string code4() const noexcept;
102
105 [[nodiscard]] constexpr std::string code4_open_type() const noexcept;
106
107 [[nodiscard]] constexpr friend std::string to_string(iso_15924 const &rhs) noexcept
108 {
109 return rhs.code4();
110 }
111
114 [[nodiscard]] constexpr bool left_to_right() const noexcept;
115
116 [[nodiscard]] constexpr friend bool operator==(iso_15924 const& lhs, iso_15924 const& rhs) noexcept = default;
117 [[nodiscard]] constexpr friend auto operator<=>(iso_15924 const& lhs, iso_15924 const& rhs) noexcept = default;
118
125 [[nodiscard]] constexpr friend bool matches(iso_15924 const& lhs, iso_15924 const& rhs) noexcept
126 {
127 return lhs.empty() or lhs == rhs;
128 }
129
130private:
131 uint16_t _v;
132};
133
134}} // namespace hi::inline v1
135
136hi_export template<>
137struct std::hash<hi::iso_15924> {
138 [[nodiscard]] size_t operator()(hi::iso_15924 const& rhs) const noexcept
139 {
140 return std::hash<uint16_t>{}(rhs.number());
141 }
142};
STL namespace.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
ISO-15924 script code.
Definition iso_15924_intf.hpp:23
constexpr bool left_to_right() const noexcept
Is this script written left-to-right.
Definition iso_15924_impl.hpp:349
static constexpr iso_15924 common() noexcept
Common script is used for characters that are common in different scripts.
Definition iso_15924_intf.hpp:50
constexpr uint16_t number() const noexcept
Get the iso-15924 numeric value.
Definition iso_15924_intf.hpp:94
constexpr std::string code4_open_type() const noexcept
Get the 4-letter code used by open-type.
Definition iso_15924_impl.hpp:343
static constexpr iso_15924 wildcard() noexcept
When any script is allowed.
Definition iso_15924_intf.hpp:41
constexpr friend bool matches(iso_15924 const &lhs, iso_15924 const &rhs) noexcept
Check if rhs matches with lhs.
Definition iso_15924_intf.hpp:125
static constexpr iso_15924 uncoded() noexcept
Used when the script was not encoded with the text.
Definition iso_15924_intf.hpp:57
constexpr std::string code4() const noexcept
Get the iso-15924 4-letter code.
Definition iso_15924_impl.hpp:337
T operator()(T... args)