CommonLib
Toggle main menu visibility
Loading...
Searching...
No Matches
encoding_expr.inl
Go to the documentation of this file.
1
#
include
<
bit
>
2
3
#
include
"ut/encoding_type.h"
4
#
include
"string_expr.h"
5
6
namespace
hedgedev::csl::ut::
expr
7
{
8
template
<any_string T>
9
inline
constexpr
encoding
::
encoding_type
get_char_encoding_type
()
10
{
11
using
char_type_t = get_char_type_t<T>;
12
13
if
constexpr
(
sizeof
(char_type_t) == 1)
14
{
15
return
encoding
::
utf8
;
16
}
17
else
if
constexpr
(
sizeof
(char_type_t) == 2)
18
{
19
if
constexpr
(std::endian::native == std::endian::little)
20
{
21
return
encoding
::
utf16_le
;
22
}
23
else
24
{
25
return
encoding
::
utf16_be
;
26
}
27
}
28
else
if
constexpr
(
sizeof
(char_type_t) == 4)
29
{
30
if
constexpr
(std::endian::native == std::endian::little)
31
{
32
return
encoding
::
utf32_le
;
33
}
34
else
35
{
36
return
encoding
::
utf32_be
;
37
}
38
}
39
40
return
encoding
::
unknown
;
41
}
42
43
inline
constexpr
encoding
::
encoding_type
get_native_encoding_type
(
encoding
::
encoding_type
in_encoding)
44
{
45
if
constexpr
(std::endian::native == std::endian::little)
46
{
47
switch
(in_encoding)
48
{
49
case
encoding
::
utf16_be
:
50
return
encoding
::
utf16_le
;
51
52
case
encoding
::
utf32_be
:
53
return
encoding
::
utf32_le
;
54
}
55
}
56
else
57
{
58
switch
(in_encoding)
59
{
60
case
encoding
::
utf16_le
:
61
return
encoding
::
utf16_be
;
62
63
case
encoding
::
utf32_le
:
64
return
encoding
::
utf32_be
;
65
}
66
}
67
68
return
in_encoding;
69
}
70
71
inline
constexpr
size_t
get_encoding_char_size
(
encoding
::
encoding_type
in_encoding
)
72
{
73
switch
(in_encoding)
74
{
75
case
encoding::utf8:
76
case
encoding::latin1:
77
return
sizeof
(char8_t);
78
79
case
encoding
::
utf16_le
:
80
case
encoding
::
utf16_be
:
81
return
sizeof
(
char16_t
);
82
83
case
encoding
::
utf32_le
:
84
case
encoding
::
utf32_be
:
85
return
sizeof
(
char32_t
);
86
}
87
88
return
0;
89
}
90
91
template
<any_string T>
92
inline
constexpr
bool
is_char_encoding_type
(
encoding
::
encoding_type
in_encoding)
93
{
94
return
get_char_encoding_type<T>() == in_encoding;
95
}
96
}
hedgedev::csl::ut::encoding
Definition
encoding.h:10
hedgedev::csl::ut::encoding::encoding_type
encoding_type
Definition
encoding_type.h:6
hedgedev::csl::ut::encoding::utf32_be
@ utf32_be
Definition
encoding_type.h:12
hedgedev::csl::ut::encoding::utf16_be
@ utf16_be
Definition
encoding_type.h:10
hedgedev::csl::ut::encoding::unknown
@ unknown
Definition
encoding_type.h:7
hedgedev::csl::ut::encoding::utf32_le
@ utf32_le
Definition
encoding_type.h:11
hedgedev::csl::ut::encoding::utf8
@ utf8
Definition
encoding_type.h:8
hedgedev::csl::ut::encoding::utf16_le
@ utf16_le
Definition
encoding_type.h:9
hedgedev::csl::ut::expr::get_char_encoding_type
constexpr encoding::encoding_type get_char_encoding_type()
Definition
encoding_expr.inl:9
hedgedev::csl::ut::expr::get_native_encoding_type
constexpr encoding::encoding_type get_native_encoding_type(encoding::encoding_type in_encoding)
Definition
encoding_expr.inl:43
hedgedev::csl::ut::expr::get_encoding_char_size
constexpr size_t get_encoding_char_size(encoding::encoding_type in_encoding)
Definition
encoding_expr.inl:71
hedgedev::csl::ut::expr::is_char_encoding_type
constexpr bool is_char_encoding_type(encoding::encoding_type in_encoding)
Definition
encoding_expr.inl:92
hedgedev::csl::ut
Definition
expr.h:7
include
ut
expr
encoding_expr.inl
Generated by
1.18.0