7#include "../utility/utility.hpp"
8#include "../macros.hpp"
11hi_export_module(hikogui.i18n.iso_639);
13namespace hi::inline
v1 {
25hi_export
class iso_639 {
33 template<std::
size_t I>
34 constexpr friend iso_639&
set(iso_639& rhs,
char c)
37 c == 0 or (c >=
'a' and c <=
'z') or (c >=
'A' and c <=
'Z') or (c >=
'1' and c <=
'5'),
38 "Must be letters or the digits between '1' and '5', or nul");
42 (c >=
'a' and c <=
'z') ? c -
'a' + 1 :
43 (c >=
'A' and c <=
'Z') ? c -
'A' + 1 :
44 (c >=
'1' and c <=
'5') ? c -
'1' + 27 :
49 constexpr auto shift = I * 5;
50 rhs._v &= ~(0x1f <<
shift);
61 template<std::
size_t I>
62 [[nodiscard]]
constexpr friend char get(iso_639
const& rhs)
noexcept
64 constexpr auto shift = I * 5;
65 hilet x = (rhs._v >>
shift) & 0x1f;
69 return 'a' + narrow_cast<char>(x - 1);
71 return '1' + narrow_cast<char>(x - 27);
82 constexpr iso_639() noexcept : _v(0) {}
86 constexpr iso_639(std::string_view str) : _v(0)
89 hi_check(str.size() == 2 or str.size() == 3,
"ISO-639 incorrect length.");
93 if (str.size() == 3) {
97 throw parse_error(std::format(
"A ISO-639 language code must be 2 or 3 letters in length, got '{}'", str));
101 constexpr iso_639(intrinsic_t, uint16_t v) noexcept : _v(v) {}
103 [[nodiscard]]
constexpr uint16_t
const& intrinsic() const noexcept
108 [[nodiscard]]
constexpr uint16_t& intrinsic() noexcept
119 hilet tmp = _v & 0x7fff;
131 [[nodiscard]]
constexpr bool empty() const noexcept
138 constexpr explicit operator bool() const noexcept
145 [[nodiscard]]
size_t hash() const noexcept
172 [[nodiscard]]
constexpr friend bool operator==(iso_639
const& lhs, iso_639
const& rhs)
noexcept =
default;
176 [[nodiscard]]
constexpr friend auto operator<=>(iso_639
const& lhs, iso_639
const& rhs)
noexcept =
default;
184 [[nodiscard]]
constexpr friend bool matches(iso_639
const& lhs, iso_639
const& rhs)
noexcept
186 return lhs.empty() or lhs == rhs;
206 [[nodiscard]]
size_t operator()(hi::iso_639
const& rhs)
const noexcept
DOXYGEN BUG.
Definition algorithm.hpp:16
@ shift
The shift key is being held.
Definition keyboard_modifiers.hpp:23
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
ISO-639 language code.
Definition iso_639.hpp:25
constexpr friend bool matches(iso_639 const &lhs, iso_639 const &rhs) noexcept
Check if rhs matches with lhs.
Definition iso_639.hpp:184
constexpr std::string code() const noexcept
Get the 2 or 3 letter ISO-639 code.
Definition iso_639.hpp:152
constexpr bool empty() const noexcept
Check if the language is empty.
Definition iso_639.hpp:131
size_t hash() const noexcept
Get the hash value for this language code.
Definition iso_639.hpp:145
constexpr friend char get(iso_639 const &rhs) noexcept
Get the letter at a specific position.
Definition iso_639.hpp:62
constexpr friend iso_639 & set(iso_639 &rhs, char c)
Set the letter at a specific position.
Definition iso_639.hpp:34
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:86
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:117