7#include "iso_15924.hpp"
10#include "../utility/module.hpp"
11#include "../generator.hpp"
12#include "../ranges.hpp"
16namespace hi::inline
v1 {
30 uint16_t _reserved = 0;
39 language(language), script(script), region(region)
67 [[nodiscard]]
bool empty() const noexcept
69 return language.
empty() and script.empty() and region.empty();
74 explicit operator bool() const noexcept
89 if (script and region) {
93 if (script or region) {
108 hilet check = expand();
110 if (tag.expand() == check) {
124 for (
hilet expanded_variant : variant.expand().variants()) {
125 if (
std::find(r.begin(), r.end(), expanded_variant) == r.end()) {
126 r.push_back(expanded_variant);
143 auto last_variant = *
this;
144 for (
hilet& variant : canonical_variants()) {
145 last_variant = variant;
156 return expand().script;
165 return default_script().left_to_right();
168 [[nodiscard]]
std::string to_string() const noexcept
171 r += language.
code();
187 if (lhs.language != rhs.language) {
190 if (lhs.script and rhs.script and lhs.script != rhs.script) {
193 if (lhs.region and rhs.region and lhs.region != rhs.region) {
216 [[nodiscard]]
size_t operator()(hi::language_tag
const& rhs)
const noexcept
225template<
typename CharT>
226struct std::formatter<
hi::language_tag, CharT> : std::formatter<std::string_view, CharT> {
227 auto format(hi::language_tag
const& t,
auto& fc)
229 return std::formatter<std::string_view, CharT>::format(t.to_string(), fc);
234template<
typename CharT>
235struct std::formatter<
std::
vector<hi::language_tag>, CharT> : std::formatter<std::string_view, CharT> {
239 for (
hilet language : t) {
243 r += std::format(
"{}", language);
245 return std::formatter<std::string_view, CharT>::format(r, fc);
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
constexpr std::vector< Value > make_vector(Range &&range)
Make a vector from a view.
Definition ranges.hpp:43
std::vector< language_tag > variants(std::vector< language_tag > languages)
Add variants to the list of languages.
geometry/margins.hpp
Definition cache.hpp:11
A return value for a generator-function.
Definition generator.hpp:29
ISO-15924 script code.
Definition iso_15924.hpp:17
std::string_view code4() const noexcept
Get the iso-15924 4-letter code.
ISO-3166 country code.
Definition iso_3166.hpp:15
ISO-639 language code.
Definition iso_639.hpp:23
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
The IETF BCP 47 language tag.
Definition language_tag.hpp:25
bool empty() const noexcept
Check if the language tag is empty.
Definition language_tag.hpp:67
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:106
generator< language_tag > variants() const noexcept
Get variants of the language_tag.
Definition language_tag.hpp:86
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:118
static language_tag parse(std::string_view str)
Parse the language, script and region raw from the string.
bool left_to_right() const noexcept
The language direction for this language-tag.
Definition language_tag.hpp:163
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:185
iso_15924 default_script() const noexcept
Get the default-script for this language.
Definition language_tag.hpp:154