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 <string_view>
10#include <cstdint>
11#include <format>
12
13namespace hi::inline v1 {
14
18class iso_15924 {
19public:
20 constexpr iso_15924() noexcept : _v(999) {}
21 constexpr iso_15924(iso_15924 const &) noexcept = default;
22 constexpr iso_15924(iso_15924 &&) noexcept = default;
23 constexpr iso_15924 &operator=(iso_15924 const &) noexcept = default;
24 constexpr iso_15924 &operator=(iso_15924 &&) noexcept = default;
25
26 constexpr iso_15924(uint16_t number) : _v(number) {
27 if (number > 999) {
28 throw parse_error(std::format("Invalid script number '{}'", number));
29 }
30 }
31
32 iso_15924(unicode_script const &script) noexcept;
33 iso_15924(std::string_view code4);
34
35 [[nodiscard]] constexpr bool empty() const noexcept
36 {
37 return _v == 999;
38 }
39
40 explicit operator bool() const noexcept
41 {
42 return not empty();
43 }
44
47 [[nodiscard]] constexpr uint16_t number() const noexcept {
48 return _v;
49 }
50
53 [[nodiscard]] std::string_view code4() const noexcept;
54
57 [[nodiscard]] std::string_view code4_open_type() const noexcept;
58
59 [[nodiscard]] constexpr friend bool operator==(iso_15924 const &lhs, iso_15924 const &rhs) noexcept = default;
60
61private:
62 uint16_t _v;
63};
64
65} // namespace hi::inline v1
66
67template<>
68struct std::hash<hi::iso_15924> {
69 [[nodiscard]] size_t operator()(hi::iso_15924 const &rhs) const noexcept
70 {
71 return std::hash<uint16_t>{}(rhs.number());
72 }
73};
STL namespace.
Exception thrown during parsing on an error.
Definition exception.hpp:25
ISO-15924 script code.
Definition iso_15924.hpp:18
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:47