HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
to_string.hpp
Go to the documentation of this file.
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
9#pragma once
10
11#include "utf_8.hpp"
12#include "utf_16.hpp"
13#include "utf_32.hpp"
14#include <string>
15#include <string_view>
16#include <climits>
17
18namespace hi { inline namespace v1 {
19
23[[nodiscard]] constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
24{
25 return char_converter<"utf-32", "utf-32">{}(rhs);
26}
27
31[[nodiscard]] constexpr std::u32string to_u32string(std::u16string_view rhs) noexcept
32{
33 return char_converter<"utf-16", "utf-32">{}(rhs);
34}
35
39[[nodiscard]] constexpr std::u32string to_u32string(std::u8string_view rhs) noexcept
40{
41 return char_converter<"utf-8", "utf-32">{}(rhs);
42}
43
47[[nodiscard]] constexpr std::u32string to_u32string(std::wstring_view rhs) noexcept
48{
49#if WCHAR_MAX >= 0x10'ffff
50 return char_converter<"utf-32", "utf-32">{}(rhs);
51#else
52 return char_converter<"utf-16", "utf-32">{}(rhs);
53#endif
54}
55
59[[nodiscard]] constexpr std::u32string to_u32string(std::string_view rhs) noexcept
60{
61 return char_converter<"utf-8", "utf-32">{}(rhs);
62}
63
67[[nodiscard]] constexpr std::u16string to_u16string(std::u32string_view rhs) noexcept
68{
69 return char_converter<"utf-32", "utf-16">{}(rhs);
70}
71
75[[nodiscard]] constexpr std::u16string to_u16string(std::u16string_view rhs) noexcept
76{
77 return char_converter<"utf-16", "utf-16">{}(rhs);
78}
79
83[[nodiscard]] constexpr std::u16string to_u16string(std::u8string_view rhs) noexcept
84{
85 return char_converter<"utf-8", "utf-16">{}(rhs);
86}
87
91[[nodiscard]] constexpr std::u16string to_u16string(std::wstring_view rhs) noexcept
92{
93#if WCHAR_MAX >= 0x10'ffff
94 return char_converter<"utf-32", "utf-16">{}(rhs);
95#else
96 return char_converter<"utf-16", "utf-16">{}(rhs);
97#endif
98}
99
103[[nodiscard]] constexpr std::u16string to_u16string(std::string_view rhs) noexcept
104{
105 return char_converter<"utf-8", "utf-16">{}(rhs);
106}
107
111[[nodiscard]] constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
112{
113 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
114}
115
119[[nodiscard]] constexpr std::u8string to_u8string(std::u16string_view rhs) noexcept
120{
121 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
122}
123
127[[nodiscard]] constexpr std::u8string to_u8string(std::u8string_view rhs) noexcept
128{
129 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
130}
131
135[[nodiscard]] constexpr std::u8string to_u8string(std::wstring_view rhs) noexcept
136{
137#if WCHAR_MAX >= 0x10'ffff
138 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
139#else
140 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
141#endif
142}
143
147[[nodiscard]] constexpr std::u8string to_u8string(std::string_view rhs) noexcept
148{
149 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
150}
151
155[[nodiscard]] constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
156{
157#if WCHAR_MAX >= 0x10'ffff
158 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
159#else
160 return char_converter<"utf-32", "utf-16">{}.convert<std::wstring>(rhs);
161#endif
162}
163
167[[nodiscard]] constexpr std::wstring to_wstring(std::u16string_view rhs) noexcept
168{
169#if WCHAR_MAX >= 0x10'ffff
170 return char_converter<"utf-16", "utf-32">{}.convert<std::wstring>(rhs);
171#else
172 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
173#endif
174}
175
179[[nodiscard]] constexpr std::wstring to_wstring(std::u8string_view rhs) noexcept
180{
181#if WCHAR_MAX >= 0x10'ffff
182 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
183#else
184 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
185#endif
186}
187
191[[nodiscard]] constexpr std::wstring to_wstring(std::wstring_view rhs) noexcept
192{
193#if WCHAR_MAX >= 0x10'ffff
194 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
195#else
196 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
197#endif
198}
199
203[[nodiscard]] constexpr std::wstring to_wstring(std::string_view rhs) noexcept
204{
205#if WCHAR_MAX >= 0x10'ffff
206 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
207#else
208 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
209#endif
210}
211
215[[nodiscard]] constexpr std::string to_string(std::u32string_view rhs) noexcept
216{
217 return char_converter<"utf-32", "utf-8">{}(rhs);
218}
219
223[[nodiscard]] constexpr std::string to_string(std::u16string_view rhs) noexcept
224{
225 return char_converter<"utf-16", "utf-8">{}(rhs);
226}
227
231[[nodiscard]] constexpr std::string to_string(std::u8string_view rhs) noexcept
232{
233 return char_converter<"utf-8", "utf-8">{}(rhs);
234}
235
239[[nodiscard]] constexpr std::string to_string(std::wstring_view rhs) noexcept
240{
241#if WCHAR_MAX >= 0x10'ffff
242 return char_converter<"utf-32", "utf-8">{}(rhs);
243#else
244 return char_converter<"utf-16", "utf-8">{}(rhs);
245#endif
246}
247
251[[nodiscard]] constexpr std::string to_string(std::string_view rhs) noexcept
252{
253 return char_converter<"utf-8", "utf-8">{}(rhs);
254}
255
256}} // namespace hi::v1
Definition of the Unicode UTF-32 encoding.
Definition of the Unicode UTF-8 encoding.
Definition of the Unicode UTF-16 encoding.
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
constexpr std::u16string to_u16string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-16.
Definition to_string.hpp:67
constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
Identity conversion from UTF-32 to UTF-32.
Definition to_string.hpp:23
constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:111
constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
Conversion from UTF-32 to wide-string (UTF-16/32).
Definition to_string.hpp:155
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A converter between character encodings.
Definition char_converter.hpp:92
constexpr OutRange convert(InRange &&src) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:108