HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
to_string.hpp
1// Copyright Take Vos 2022.
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 "utf_8.hpp"
8#include "utf_16.hpp"
9#include "utf_32.hpp"
10#include <string>
11#include <string_view>
12#include <climits>
13
14namespace hi::inline v1 {
15
16[[nodiscard]] constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
17{
18 return char_converter<"utf-32", "utf-32">{}(rhs);
19}
20
21[[nodiscard]] constexpr std::u32string to_u32string(std::u16string_view rhs) noexcept
22{
23 return char_converter<"utf-16", "utf-32">{}(rhs);
24}
25
26[[nodiscard]] constexpr std::u32string to_u32string(std::u8string_view rhs) noexcept
27{
28 return char_converter<"utf-8", "utf-32">{}(rhs);
29}
30
31[[nodiscard]] constexpr std::u32string to_u32string(std::wstring_view rhs) noexcept
32{
33#if WCHAR_MAX >= 0x10'ffff
34 return char_converter<"utf-32", "utf-32">{}(rhs);
35#else
36 return char_converter<"utf-16", "utf-32">{}(rhs);
37#endif
38}
39
40[[nodiscard]] constexpr std::u32string to_u32string(std::string_view rhs) noexcept
41{
42 return char_converter<"utf-8", "utf-32">{}(rhs);
43}
44
45[[nodiscard]] constexpr std::u16string to_u16string(std::u32string_view rhs) noexcept
46{
47 return char_converter<"utf-32", "utf-16">{}(rhs);
48}
49
50[[nodiscard]] constexpr std::u16string to_u16string(std::u16string_view rhs) noexcept
51{
52 return char_converter<"utf-16", "utf-16">{}(rhs);
53}
54
55[[nodiscard]] constexpr std::u16string to_u16string(std::u8string_view rhs) noexcept
56{
57 return char_converter<"utf-8", "utf-16">{}(rhs);
58}
59
60[[nodiscard]] constexpr std::u16string to_u16string(std::wstring_view rhs) noexcept
61{
62#if WCHAR_MAX >= 0x10'ffff
63 return char_converter<"utf-32", "utf-16">{}(rhs);
64#else
65 return char_converter<"utf-16", "utf-16">{}(rhs);
66#endif
67}
68
69[[nodiscard]] constexpr std::u16string to_u16string(std::string_view rhs) noexcept
70{
71 return char_converter<"utf-8", "utf-16">{}(rhs);
72}
73
74[[nodiscard]] constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
75{
76 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
77}
78
79[[nodiscard]] constexpr std::u8string to_u8string(std::u16string_view rhs) noexcept
80{
81 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
82}
83
84[[nodiscard]] constexpr std::u8string to_u8string(std::u8string_view rhs) noexcept
85{
86 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
87}
88
89[[nodiscard]] constexpr std::u8string to_u8string(std::wstring_view rhs) noexcept
90{
91#if WCHAR_MAX >= 0x10'ffff
92 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
93#else
94 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
95#endif
96}
97
98[[nodiscard]] constexpr std::u8string to_u8string(std::string_view rhs) noexcept
99{
100 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
101}
102
103[[nodiscard]] constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
104{
105#if WCHAR_MAX >= 0x10'ffff
106 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
107#else
108 return char_converter<"utf-32", "utf-16">{}.convert<std::wstring>(rhs);
109#endif
110}
111
112[[nodiscard]] constexpr std::wstring to_wstring(std::u16string_view rhs) noexcept
113{
114#if WCHAR_MAX >= 0x10'ffff
115 return char_converter<"utf-16", "utf-32">{}.convert<std::wstring>(rhs);
116#else
117 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
118#endif
119}
120
121[[nodiscard]] constexpr std::wstring to_wstring(std::u8string_view rhs) noexcept
122{
123#if WCHAR_MAX >= 0x10'ffff
124 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
125#else
126 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
127#endif
128}
129
130[[nodiscard]] constexpr std::wstring to_wstring(std::wstring_view rhs) noexcept
131{
132#if WCHAR_MAX >= 0x10'ffff
133 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
134#else
135 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
136#endif
137}
138
139[[nodiscard]] constexpr std::wstring to_wstring(std::string_view rhs) noexcept
140{
141#if WCHAR_MAX >= 0x10'ffff
142 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
143#else
144 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
145#endif
146}
147
148[[nodiscard]] constexpr std::string to_string(std::u32string_view rhs) noexcept
149{
150 return char_converter<"utf-32", "utf-8">{}(rhs);
151}
152
153[[nodiscard]] constexpr std::string to_string(std::u16string_view rhs) noexcept
154{
155 return char_converter<"utf-16", "utf-8">{}(rhs);
156}
157
158[[nodiscard]] constexpr std::string to_string(std::u8string_view rhs) noexcept
159{
160 return char_converter<"utf-8", "utf-8">{}(rhs);
161}
162
163[[nodiscard]] constexpr std::string to_string(std::wstring_view rhs) noexcept
164{
165#if WCHAR_MAX >= 0x10'ffff
166 return char_converter<"utf-32", "utf-8">{}(rhs);
167#else
168 return char_converter<"utf-16", "utf-8">{}(rhs);
169#endif
170}
171
172[[nodiscard]] constexpr std::string to_string(std::string_view rhs) noexcept
173{
174 return char_converter<"utf-8", "utf-8">{}(rhs);
175}
176
177} // namespace hi::inline v1
T to_string(T... args)
T to_wstring(T... args)