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 "../exception.hpp"
9#include "../unicode/unicode_bidi_class.hpp"
10#include <string_view>
11#include <cstdint>
12#include <format>
13
14namespace hi::inline v1 {
15
19class iso_15924 {
20public:
21 constexpr iso_15924() noexcept : _v(999) {}
22 constexpr iso_15924(iso_15924 const &) noexcept = default;
23 constexpr iso_15924(iso_15924 &&) noexcept = default;
24 constexpr iso_15924 &operator=(iso_15924 const &) noexcept = default;
25 constexpr iso_15924 &operator=(iso_15924 &&) noexcept = default;
26
27 constexpr iso_15924(uint16_t number) : _v(number) {
28 if (number > 999) {
29 throw parse_error(std::format("Invalid script number '{}'", number));
30 }
31 }
32
33 iso_15924(unicode_script const &script) noexcept;
34 iso_15924(std::string_view code4);
35
36 [[nodiscard]] constexpr bool empty() const noexcept
37 {
38 return _v == 999;
39 }
40
41 explicit operator bool() const noexcept
42 {
43 return not empty();
44 }
45
48 [[nodiscard]] constexpr uint16_t number() const noexcept {
49 return _v;
50 }
51
54 [[nodiscard]] std::string_view code4() const noexcept;
55
58 [[nodiscard]] std::string_view code4_open_type() const noexcept;
59
60 [[nodiscard]] unicode_bidi_class writing_direction() const noexcept;
61
62 [[nodiscard]] constexpr friend bool operator==(iso_15924 const &lhs, iso_15924 const &rhs) noexcept = default;
63
64private:
65 uint16_t _v;
66};
67
68} // namespace hi::inline v1
69
70template<>
71struct std::hash<hi::iso_15924> {
72 [[nodiscard]] size_t operator()(hi::iso_15924 const &rhs) const noexcept
73 {
74 return std::hash<uint16_t>{}(rhs.number());
75 }
76};
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
unicode_bidi_class
Bidirectional class Unicode Standard Annex #9: https://unicode.org/reports/tr9/.
Definition unicode_bidi_class.hpp:17
The HikoGUI namespace.
Definition ascii.hpp:19
ISO-15924 script code.
Definition iso_15924.hpp:19
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:48