8#include "iso_15924.hpp"
12#include "../generator.hpp"
13#include "../ranges.hpp"
17namespace hi::inline v1 {
31 uint16_t _reserved = 0;
68 [[nodiscard]]
bool empty() const noexcept
70 return language.empty() and script.empty() and region.empty();
75 explicit operator bool() const noexcept
90 if (script and region) {
94 if (script or region) {
109 hilet check = expand();
110 for (
hilet& tag : variants()) {
111 if (tag.expand() == check) {
121 auto r = make_vector(variants());
124 for (
hilet variant : variants()) {
125 for (
hilet expanded_variant : variant.expand().variants()) {
126 if (
std::find(r.begin(), r.end(), expanded_variant) == r.end()) {
127 r.push_back(expanded_variant);
144 auto last_variant = *
this;
145 for (
hilet& variant : canonical_variants()) {
146 last_variant = variant;
151 [[nodiscard]]
std::string to_string() const noexcept
154 r += language.
code();
170 if (lhs.language != rhs.language) {
173 if (lhs.script and rhs.script and lhs.script != rhs.script) {
176 if (lhs.region and rhs.region and lhs.region != rhs.region) {
199 [[nodiscard]]
size_t operator()(hi::language_tag
const& rhs)
const noexcept
208template<
typename CharT>
209struct std::formatter<hi::language_tag, CharT> : std::formatter<std::string_view, CharT> {
210 auto format(hi::language_tag
const& t,
auto& fc)
212 return std::formatter<std::string_view, CharT>::format(t.to_string(), fc);
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
A return value for a generator-function.
Definition generator.hpp:28
ISO-15924 script code.
Definition iso_15924.hpp:18
std::string_view code4() const noexcept
Get the iso-15924 4-letter code.
ISO-3166 country code.
Definition iso_3166.hpp:16
ISO-639 language code.
Definition iso_639.hpp:25
constexpr std::string code() const noexcept
Get the 2 or 3 letter ISO-639 code.
Definition iso_639.hpp:140
Definition language.hpp:18
The IETF BCP 47 language tag.
Definition language_tag.hpp:26
bool empty() const noexcept
Check if the language tag is empty.
Definition language_tag.hpp:68
language_tag(std::string_view str)
Parse a language tag.
language_tag expand() const noexcept
Expand the language tag to include script and language.
generator< language_tag > canonical_variants() const noexcept
Get variants of the language_tag.
Definition language_tag.hpp:107
generator< language_tag > variants() const noexcept
Get variants of the language_tag.
Definition language_tag.hpp:87
std::vector< language_tag > all_variants() const noexcept
Creates variants of a language tag, including those by expanding the normal variants.
Definition language_tag.hpp:119
static language_tag parse(std::string_view str)
Parse the language, script and region raw from the string.
constexpr friend bool match(language_tag const &lhs, language_tag const &rhs) noexcept
Check if two language_tags match for their non-empty fields.
Definition language_tag.hpp:168
T operator()(T... args)
Definition datum.hpp:2458