7#include "../utility/utility.hpp"
8#include "../macros.hpp"
15hi_export_module(hikogui.i18n.iso_639);
17hi_export
namespace hi::inline
v1 {
37 template<std::
size_t I>
40 if (not (c == 0 or (c >=
'a' and c <=
'z') or (c >=
'A' and c <=
'Z') or (c >=
'1' and c <=
'5'))) {
47 (c >=
'a' and c <=
'z') ? c -
'a' + 1 :
48 (c >=
'A' and c <=
'Z') ? c -
'A' + 1 :
49 (c >=
'1' and c <=
'5') ? c -
'1' + 27 :
54 constexpr auto shift = I * 5;
55 rhs._v &= ~(0x1f <<
shift);
66 template<std::
size_t I>
67 [[nodiscard]]
constexpr friend char get(
iso_639 const& rhs)
noexcept
69 constexpr auto shift = I * 5;
70 auto const x = (rhs._v >>
shift) & 0x1f;
74 return 'a' + narrow_cast<char>(x - 1);
76 return '1' + narrow_cast<char>(x - 27);
91 constexpr iso_639(std::string_view str) : _v(0)
93 if (str.size() != 2 and str.size() != 3) {
94 throw parse_error(
"ISO-639 incorrect length.");
97 if (not set<0>(*
this, str[0])) {
98 throw parse_error(
"Must be letters or the digits between '1' and '5', or nul.");
101 if (not set<1>(*
this, str[1])) {
102 throw parse_error(
"Must be letters or the digits between '1' and '5', or nul.");
105 if (str.size() == 3) {
106 if (not set<2>(*
this, str[2])) {
107 throw parse_error(
"Must be letters or the digits between '1' and '5', or nul.");
112 constexpr iso_639(std::in_place_t, uint16_t v) noexcept : _v(v) {}
114 [[nodiscard]]
constexpr uint16_t
const& intrinsic() const noexcept
119 [[nodiscard]]
constexpr uint16_t& intrinsic() noexcept
130 auto const tmp = _v & 0x7fff;
142 [[nodiscard]]
constexpr bool empty() const noexcept
149 constexpr explicit operator bool() const noexcept
156 [[nodiscard]]
size_t hash() const noexcept
197 return lhs.empty() or lhs == rhs;
217 [[nodiscard]]
size_t operator()(hi::iso_639
const& rhs)
const noexcept
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
@ shift
The shift key is being held.
ISO-639 language code.
Definition iso_639.hpp:29
constexpr friend bool matches(iso_639 const &lhs, iso_639 const &rhs) noexcept
Check if rhs matches with lhs.
Definition iso_639.hpp:195
constexpr std::string code() const noexcept
Get the 2 or 3 letter ISO-639 code.
Definition iso_639.hpp:163
constexpr bool empty() const noexcept
Check if the language is empty.
Definition iso_639.hpp:142
constexpr friend bool set(iso_639 &rhs, char c) noexcept
Set the letter at a specific position.
Definition iso_639.hpp:38
size_t hash() const noexcept
Get the hash value for this language code.
Definition iso_639.hpp:156
constexpr friend char get(iso_639 const &rhs) noexcept
Get the letter at a specific position.
Definition iso_639.hpp:67
constexpr friend auto operator<=>(iso_639 const &lhs, iso_639 const &rhs) noexcept=default
Compare two language codes.
constexpr iso_639(std::string_view str)
Construct a language from the 2 or 3 letter code.
Definition iso_639.hpp:91
constexpr friend bool operator==(iso_639 const &lhs, iso_639 const &rhs) noexcept=default
Compare two language codes.
constexpr std::size_t size() const noexcept
Get the number of character.
Definition iso_639.hpp:128