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 "../utility/utility.hpp"
15#include "../macros.hpp"
16#include <string>
17#include <string_view>
18#include <climits>
19#include <array>
20
21hi_export_module(hikogui.char_maps.to_string);
22
23hi_export namespace hi { inline namespace v1 {
24
28[[nodiscard]] constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
29{
30 return char_converter<"utf-32", "utf-32">{}(rhs);
31}
32
36[[nodiscard]] constexpr std::u32string to_u32string(std::u16string_view rhs) noexcept
37{
38 return char_converter<"utf-16", "utf-32">{}(rhs);
39}
40
44[[nodiscard]] constexpr std::u32string to_u32string(std::u8string_view rhs) noexcept
45{
46 return char_converter<"utf-8", "utf-32">{}(rhs);
47}
48
52[[nodiscard]] constexpr std::u32string to_u32string(std::wstring_view rhs) noexcept
53{
54#if WCHAR_MAX >= 0x10'ffff
55 return char_converter<"utf-32", "utf-32">{}(rhs);
56#else
57 return char_converter<"utf-16", "utf-32">{}(rhs);
58#endif
59}
60
64[[nodiscard]] constexpr std::u32string to_u32string(std::string_view rhs) noexcept
65{
66 return char_converter<"utf-8", "utf-32">{}(rhs);
67}
68
72[[nodiscard]] constexpr std::u16string to_u16string(std::u32string_view rhs) noexcept
73{
74 return char_converter<"utf-32", "utf-16">{}(rhs);
75}
76
80[[nodiscard]] constexpr std::u16string to_u16string(std::u16string_view rhs) noexcept
81{
82 return char_converter<"utf-16", "utf-16">{}(rhs);
83}
84
88[[nodiscard]] constexpr std::u16string to_u16string(std::u8string_view rhs) noexcept
89{
90 return char_converter<"utf-8", "utf-16">{}(rhs);
91}
92
96[[nodiscard]] constexpr std::u16string to_u16string(std::wstring_view rhs) noexcept
97{
98#if WCHAR_MAX >= 0x10'ffff
99 return char_converter<"utf-32", "utf-16">{}(rhs);
100#else
101 return char_converter<"utf-16", "utf-16">{}(rhs);
102#endif
103}
104
108[[nodiscard]] constexpr std::u16string to_u16string(std::string_view rhs) noexcept
109{
110 return char_converter<"utf-8", "utf-16">{}(rhs);
111}
112
116[[nodiscard]] constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
117{
118 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
119}
120
124[[nodiscard]] constexpr std::u8string to_u8string(std::u16string_view rhs) noexcept
125{
126 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
127}
128
132[[nodiscard]] constexpr std::u8string to_u8string(std::u8string_view rhs) noexcept
133{
134 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
135}
136
140[[nodiscard]] constexpr std::u8string to_u8string(std::wstring_view rhs) noexcept
141{
142#if WCHAR_MAX >= 0x10'ffff
143 return char_converter<"utf-32", "utf-8">{}.convert<std::u8string>(rhs);
144#else
145 return char_converter<"utf-16", "utf-8">{}.convert<std::u8string>(rhs);
146#endif
147}
148
152[[nodiscard]] constexpr std::u8string to_u8string(std::string_view rhs) noexcept
153{
154 return char_converter<"utf-8", "utf-8">{}.convert<std::u8string>(rhs);
155}
156
160[[nodiscard]] constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
161{
162#if WCHAR_MAX >= 0x10'ffff
163 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
164#else
165 return char_converter<"utf-32", "utf-16">{}.convert<std::wstring>(rhs);
166#endif
167}
168
172[[nodiscard]] constexpr std::wstring to_wstring(std::u16string_view rhs) noexcept
173{
174#if WCHAR_MAX >= 0x10'ffff
175 return char_converter<"utf-16", "utf-32">{}.convert<std::wstring>(rhs);
176#else
177 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
178#endif
179}
180
184[[nodiscard]] constexpr std::wstring to_wstring(std::u8string_view rhs) noexcept
185{
186#if WCHAR_MAX >= 0x10'ffff
187 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
188#else
189 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
190#endif
191}
192
196[[nodiscard]] constexpr std::wstring to_wstring(std::wstring_view rhs) noexcept
197{
198#if WCHAR_MAX >= 0x10'ffff
199 return char_converter<"utf-32", "utf-32">{}.convert<std::wstring>(rhs);
200#else
201 return char_converter<"utf-16", "utf-16">{}.convert<std::wstring>(rhs);
202#endif
203}
204
208[[nodiscard]] constexpr std::wstring to_wstring(std::string_view rhs) noexcept
209{
210#if WCHAR_MAX >= 0x10'ffff
211 return char_converter<"utf-8", "utf-32">{}.convert<std::wstring>(rhs);
212#else
213 return char_converter<"utf-8", "utf-16">{}.convert<std::wstring>(rhs);
214#endif
215}
216
220[[nodiscard]] constexpr std::string to_string(std::u32string_view rhs) noexcept
221{
222 return char_converter<"utf-32", "utf-8">{}(rhs);
223}
224
228[[nodiscard]] constexpr std::string to_string(std::u16string_view rhs) noexcept
229{
230 return char_converter<"utf-16", "utf-8">{}(rhs);
231}
232
236[[nodiscard]] constexpr std::string to_string(std::u8string_view rhs) noexcept
237{
238 return char_converter<"utf-8", "utf-8">{}(rhs);
239}
240
244[[nodiscard]] constexpr std::string to_string(std::wstring_view rhs) noexcept
245{
246#if WCHAR_MAX >= 0x10'ffff
247 return char_converter<"utf-32", "utf-8">{}(rhs);
248#else
249 return char_converter<"utf-16", "utf-8">{}(rhs);
250#endif
251}
252
256[[nodiscard]] constexpr std::string to_string(std::string_view rhs) noexcept
257{
258 return char_converter<"utf-8", "utf-8">{}(rhs);
259}
260
261}} // 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:72
constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
Identity conversion from UTF-32 to UTF-32.
Definition to_string.hpp:28
constexpr std::u8string to_u8string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:116
constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
Conversion from UTF-32 to wide-string (UTF-16/32).
Definition to_string.hpp:160
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
A converter between character encodings.
Definition char_converter.hpp:98
constexpr OutRange convert(InRange &&src) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:114