HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
ttauri
text
language_tag.hpp
1
// Copyright Take Vos 2020.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5
#pragma once
6
7
#include <string>
8
#include <ostream>
9
#include "../strings.hpp"
10
11
namespace
tt {
12
15
class
language_tag
{
16
public
:
17
language_tag
(
language_tag
const
&other)
noexcept
=
default
;
18
language_tag
(
language_tag
&&other)
noexcept
=
default
;
19
language_tag
&operator=(
language_tag
const
&other)
noexcept
=
default
;
20
language_tag
&operator=(
language_tag
&&other)
noexcept
=
default
;
21
22
language_tag
() noexcept : tag() {}
23
explicit
language_tag
(
std::string
tag) noexcept : tag(
std::move
(tag)) {}
24
explicit
language_tag
(std::string_view tag) noexcept : tag(tag) {}
25
explicit
language_tag
(
char
const
*tag) noexcept : tag(tag) {}
26
27
[[nodiscard]]
size_t
hash()
const
noexcept
28
{
29
return
std::hash<std::string>
{}(tag);
30
}
31
32
explicit
operator
bool()
const
noexcept
33
{
34
return
size(tag) != 0;
35
}
36
37
[[nodiscard]]
language_tag
short_tag()
const
noexcept
38
{
39
return
language_tag
{split(tag,
'-'
).front()};
40
}
41
42
[[nodiscard]]
bool
operator==(
language_tag
const
&rhs)
const
noexcept
43
{
44
return
tag == rhs.tag;
45
}
46
47
[[nodiscard]]
bool
operator!=(
language_tag
const
&rhs)
const
noexcept
=
default
;
48
49
[[nodiscard]]
friend
std::string
to_string(
language_tag
const
&url)
noexcept
50
{
51
return
url.tag;
52
}
53
54
friend
std::ostream
&operator<<(
std::ostream
&lhs,
language_tag
const
&rhs)
55
{
56
return
lhs << to_string(rhs);
57
}
58
59
private
:
60
std::string
tag;
61
};
62
63
}
// namespace tt
64
65
namespace
std
{
66
67
template
<>
68
class
hash
<tt::language_tag> {
69
public
:
70
[[nodiscard]]
size_t
operator()
(
tt::language_tag
const
&rhs)
const
noexcept
71
{
72
return
rhs.hash();
73
}
74
};
75
76
template
<
typename
CharT>
77
struct
std::formatter<tt::language_tag, CharT> : std::formatter<std::string_view, CharT> {
78
auto
format(
tt::language_tag
const
&t,
auto
&fc)
79
{
80
return
std::formatter<std::string_view, CharT>::format(
to_string
(t), fc);
81
}
82
};
83
84
}
// namespace std
std
STL namespace.
tt::language_tag
An IETF BCP 47 Language tag.
Definition
language_tag.hpp:15
std::ostream
std::string
std::hash
std::move
T move(T... args)
std::hash::operator()
T operator()(T... args)
std::to_string
T to_string(T... args)
Generated on Mon Apr 22 2024 12:53:38 for HikoGUI by
1.10.0