7#include "../utility/module.hpp"
8#include "../strings.hpp"
11namespace hi::inline
v1 {
31 template<std::
size_t I>
35 c == 0 or (c >=
'a' and c <=
'z') or (c >=
'A' and c <=
'Z') or (c >=
'1' and c <=
'5'),
36 "Must be letters or the digits between '1' and '5', or nul");
40 (c >=
'a' and c <=
'z') ? c -
'a' + 1 :
41 (c >=
'A' and c <=
'Z') ? c -
'A' + 1 :
42 (c >=
'1' and c <=
'5') ? c -
'1' + 27 :
47 constexpr auto shift = I * 5;
48 rhs._v &= ~(0x1f <<
shift);
59 template<std::
size_t I>
60 [[nodiscard]]
constexpr friend char get(
iso_639 const& rhs)
noexcept
62 constexpr auto shift = I * 5;
67 return 'a' + narrow_cast<char>(x - 1);
69 return '1' + narrow_cast<char>(x - 27);
84 constexpr iso_639(std::string_view str) : _v(0)
87 hi_check(str.size() == 2 or str.size() == 3,
"ISO-639 incorrect length.");
89 set<0>(*
this, str[0]);
90 set<1>(*
this, str[1]);
91 if (str.size() == 3) {
92 set<2>(*
this, str[2]);
95 throw parse_error(std::format(
"A ISO-639 language code must be 2 or 3 letters in length, got '{}'", str));
99 constexpr iso_639(intrinsic_t, uint16_t v) noexcept : _v(v) {}
101 [[nodiscard]]
constexpr uint16_t
const& intrinsic() const noexcept
106 [[nodiscard]]
constexpr uint16_t& intrinsic() noexcept
117 hilet tmp = _v & 0x7fff;
129 [[nodiscard]]
constexpr bool empty() const noexcept
136 constexpr explicit operator bool() const noexcept
143 [[nodiscard]]
size_t hash() const noexcept
179 return lhs.empty() or lhs == rhs;
199 [[nodiscard]]
size_t operator()(hi::iso_639
const& rhs)
const noexcept
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:110
#define hi_assert(expression,...)
Assert if expression is true.
Definition assert.hpp:199
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
@ shift
The shift key is being held.
geometry/margins.hpp
Definition cache.hpp:11
ISO-639 language code.
Definition iso_639.hpp:23
constexpr friend bool matches(iso_639 const &lhs, iso_639 const &rhs) noexcept
Check if rhs matches with lhs.
Definition iso_639.hpp:177
constexpr std::string code() const noexcept
Get the 2 or 3 letter ISO-639 code.
Definition iso_639.hpp:150
constexpr bool empty() const noexcept
Check if the language is empty.
Definition iso_639.hpp:129
size_t hash() const noexcept
Get the hash value for this language code.
Definition iso_639.hpp:143
constexpr friend char get(iso_639 const &rhs) noexcept
Get the letter at a specific position.
Definition iso_639.hpp:60
constexpr friend iso_639 & set(iso_639 &rhs, char c)
Set the letter at a specific position.
Definition iso_639.hpp:32
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:84
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:115