CommonLib
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
6namespace hedgedev::csl::ut::expr
7{
8 template <any_string T>
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
44 {
45 if constexpr (std::endian::native == std::endian::little)
46 {
47 switch (in_encoding)
48 {
50 return encoding::utf16_le;
51
53 return encoding::utf32_le;
54 }
55 }
56 else
57 {
58 switch (in_encoding)
59 {
61 return encoding::utf16_be;
62
64 return encoding::utf32_be;
65 }
66 }
67
68 return in_encoding;
69 }
70
72 {
73 switch (in_encoding)
74 {
75 case encoding::utf8:
76 case encoding::latin1:
77 return sizeof(char8_t);
78
81 return sizeof(char16_t);
82
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}
Definition encoding.h:10
encoding_type
Definition encoding_type.h:6
@ utf32_be
Definition encoding_type.h:12
@ utf16_be
Definition encoding_type.h:10
@ unknown
Definition encoding_type.h:7
@ utf32_le
Definition encoding_type.h:11
@ utf8
Definition encoding_type.h:8
@ utf16_le
Definition encoding_type.h:9
constexpr encoding::encoding_type get_char_encoding_type()
Definition encoding_expr.inl:9
constexpr encoding::encoding_type get_native_encoding_type(encoding::encoding_type in_encoding)
Definition encoding_expr.inl:43
constexpr size_t get_encoding_char_size(encoding::encoding_type in_encoding)
Definition encoding_expr.inl:71
constexpr bool is_char_encoding_type(encoding::encoding_type in_encoding)
Definition encoding_expr.inl:92
Definition expr.h:7