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 "../macros.hpp"
15#include <string>
16#include <string_view>
17#include <climits>
18
19namespace hi { inline namespace v1 {
20
24[[nodiscard]] constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
25{
26 return char_converter<"utf-32", "utf-32">{}(rhs);
27}
28
32[[nodiscard]] constexpr std::u32string to_u32string(std::u16string_view rhs) noexcept
33{
34 return char_converter<"utf-16", "utf-32">{}(rhs);
35}
36
40[[nodiscard]] constexpr std::u32string to_u32string(std::u8string_view rhs) noexcept
41{
42 return char_converter<"utf-8", "utf-32">{}(rhs);
43}
44
48[[nodiscard]] constexpr std::u32string to_u32string(std::wstring_view rhs) noexcept
49{
50#if WCHAR_MAX >= 0x10'ffff
51 return char_converter<"utf-32", "utf-32">{}(rhs);
52#else
53 return char_converter<"utf-16", "utf-32">{}(rhs);
54#endif
55}
56
60[[nodiscard]] constexpr std::u32string to_u32string(std::string_view rhs) noexcept
61{
62 return char_converter<"utf-8", "utf-32">{}(rhs);
63}
64
68[[nodiscard]] constexpr std::u16string to_u16string(std::u32string_view rhs) noexcept
69{
70 return char_converter<"utf-32", "utf-16">{}(rhs);
71}
72
76[[nodiscard]] constexpr std::u16string to_u16string(std::u16string_view rhs) noexcept
77{
78 return char_converter<"utf-16", "utf-16">{}(rhs);
79}
80
84[[nodiscard]] constexpr std::u16string to_u16string(std::u8string_view rhs) noexcept
85{
86 return char_converter<"utf-8", "utf-16">{}(rhs);
87}
88
92[[nodiscard]] constexpr std::u16string to_u16string(std::wstring_view rhs) noexcept
93{
94#if WCHAR_MAX >= 0x10'ffff
95 return char_converter<"utf-32", "utf-16">{}(rhs);
96#else
97 return char_converter<"utf-16", "utf-16">{}(rhs);
98#endif
99}
100
104[[nodiscard]] constexpr std::u16string to_u16string(std::string_view rhs) noexcept
105{
106 return char_converter<"utf-8", "utf-16">{}(rhs);
107}
108
112[[nodiscard]] constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
113{
114 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
115}
116
120[[nodiscard]] constexpr std::u8string to_u8string(std::u16string_view rhs) noexcept
121{
122 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
123}
124
128[[nodiscard]] constexpr std::u8string to_u8string(std::u8string_view rhs) noexcept
129{
130 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
131}
132
136[[nodiscard]] constexpr std::u8string to_u8string(std::wstring_view rhs) noexcept
137{
138#if WCHAR_MAX >= 0x10'ffff
139 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
140#else
141 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
142#endif
143}
144
148[[nodiscard]] constexpr std::u8string to_u8string(std::string_view rhs) noexcept
149{
150 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
151}
152
156[[nodiscard]] constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
157{
158#if WCHAR_MAX >= 0x10'ffff
159 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
160#else
161 return char_converter<"utf-32", "utf-16">{}.convert<std::wstring>(rhs);
162#endif
163}
164
168[[nodiscard]] constexpr std::wstring to_wstring(std::u16string_view rhs) noexcept
169{
170#if WCHAR_MAX >= 0x10'ffff
171 return char_converter<"utf-16", "utf-32">{}.convert<std::wstring>(rhs);
172#else
173 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
174#endif
175}
176
180[[nodiscard]] constexpr std::wstring to_wstring(std::u8string_view rhs) noexcept
181{
182#if WCHAR_MAX >= 0x10'ffff
183 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
184#else
185 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
186#endif
187}
188
192[[nodiscard]] constexpr std::wstring to_wstring(std::wstring_view rhs) noexcept
193{
194#if WCHAR_MAX >= 0x10'ffff
195 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
196#else
197 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
198#endif
199}
200
204[[nodiscard]] constexpr std::wstring to_wstring(std::string_view rhs) noexcept
205{
206#if WCHAR_MAX >= 0x10'ffff
207 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
208#else
209 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
210#endif
211}
212
216[[nodiscard]] constexpr std::string to_string(std::u32string_view rhs) noexcept
217{
218 return char_converter<"utf-32", "utf-8">{}(rhs);
219}
220
224[[nodiscard]] constexpr std::string to_string(std::u16string_view rhs) noexcept
225{
226 return char_converter<"utf-16", "utf-8">{}(rhs);
227}
228
232[[nodiscard]] constexpr std::string to_string(std::u8string_view rhs) noexcept
233{
234 return char_converter<"utf-8", "utf-8">{}(rhs);
235}
236
240[[nodiscard]] constexpr std::string to_string(std::wstring_view rhs) noexcept
241{
242#if WCHAR_MAX >= 0x10'ffff
243 return char_converter<"utf-32", "utf-8">{}(rhs);
244#else
245 return char_converter<"utf-16", "utf-8">{}(rhs);
246#endif
247}
248
252[[nodiscard]] constexpr std::string to_string(std::string_view rhs) noexcept
253{
254 return char_converter<"utf-8", "utf-8">{}(rhs);
255}
256
257}} // 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::u16string to_u16string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-16.
Definition to_string.hpp:68
constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
Identity conversion from UTF-32 to UTF-32.
Definition to_string.hpp:24
constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:112
constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
Conversion from UTF-32 to wide-string (UTF-16/32).
Definition to_string.hpp:156
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A converter between character encodings.
Definition char_converter.hpp:95
constexpr OutRange convert(InRange &&src) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:111