xtd 0.2.0
Loading...
Searching...
No Matches
__format_stringer.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#define __XTD_STD_INTERNAL__
7#undef __XTD_STD_INTERNAL__
9#include "../collections/generic/ienumerable.hpp"
10#include "../any.hpp"
11#include "../chrono.hpp"
12#include "../optional.hpp"
13#include "../types.hpp"
14#include <algorithm>
15#include <array>
16#include <cctype>
17#include <cstddef>
18#include <cstdint>
19#include <deque>
20#include <forward_list>
21#include <functional>
22#include <iomanip>
23#include <iostream>
24#include <locale>
25#include <list>
26#include <map>
27#include <set>
28#include <sstream>
29#include <stdexcept>
30#include <string>
31#include <system_error>
32#include <tuple>
33#include <type_traits>
34#include <typeindex>
35#include <unordered_map>
36#include <unordered_set>
37#include <utility>
38#include <valarray>
39#include <vector>
40
41
43namespace xtd {
44 class iformatable;
45 class object;
46
47 template<typename value_t>
48 inline std::string to_string(const value_t& value, const std::string& fmt, const std::locale& loc);
49 template<>
50 inline std::string to_string(const bool& value, const std::string& fmt, const std::locale& loc);
51 template<>
52 inline std::string to_string(const xtd::sbyte& value, const std::string& fmt, const std::locale& loc);
53 template<>
54 inline std::string to_string(const char& value, const std::string& fmt, const std::locale& loc);
55 template<>
56 inline std::string to_string(const unsigned char& value, const std::string& fmt, const std::locale& loc);
57 template<>
58 inline std::string to_string(const short& value, const std::string& fmt, const std::locale& loc);
59 template<>
60 inline std::string to_string(const unsigned short& value, const std::string& fmt, const std::locale& loc);
61 template<>
62 inline std::string to_string(const int& value, const std::string& fmt, const std::locale& loc);
63 template<>
64 inline std::string to_string(const unsigned int& value, const std::string& fmt, const std::locale& loc);
65 template<>
66 inline std::string to_string(const long& value, const std::string& fmt, const std::locale& loc);
67 template<>
68 inline std::string to_string(const unsigned long& value, const std::string& fmt, const std::locale& loc);
69 template<>
70 inline std::string to_string(const long long& value, const std::string& fmt, const std::locale& loc);
71 template<>
72 inline std::string to_string(const unsigned long long& value, const std::string& fmt, const std::locale& loc);
73 template<>
74 inline std::string to_string(const float& value, const std::string& fmt, const std::locale& loc);
75 template<>
76 inline std::string to_string(const double& value, const std::string& fmt, const std::locale& loc);
77 template<>
78 inline std::string to_string(const long double& value, const std::string& fmt, const std::locale& loc);
79 template<>
80 inline std::string to_string(const std::chrono::system_clock::time_point& value, const std::string& fmt, const std::locale& loc);
81 template<>
82 inline std::string to_string(const std::tm& value, const std::string& fmt, const std::locale& loc);
83 template<typename type_t, typename period_t = std::ratio<1>>
84 inline std::string to_string(const std::chrono::duration<type_t, period_t>& value, const std::string& fmt, const std::locale& loc);
85#if defined(__xtd__cpp_lib_char8_t)
86 template<>
87 inline std::string to_string(const xtd::char8& value, const std::string& fmt, const std::locale& loc);
88#endif
89 template<>
90 inline std::string to_string(const xtd::char16& value, const std::string& fmt, const std::locale& loc);
91 template<>
92 inline std::string to_string(const xtd::char32& value, const std::string& fmt, const std::locale& loc);
93 template<>
94 inline std::string to_string(const xtd::wchar& value, const std::string& fmt, const std::locale& loc);
95#if defined(__xtd__cpp_lib_three_way_comparison)
96 template<>
97 inline std::string to_string(const std::partial_ordering& value, const std::string& fmt, const std::locale& loc);
98 template<>
99 inline std::string to_string(const std::strong_ordering& value, const std::string& fmt, const std::locale& loc);
100 template<>
101 inline std::string to_string(const std::weak_ordering& value, const std::string& fmt, const std::locale& loc);
102#endif
103 template<typename value_t>
104 inline std::string to_string(const value_t* value, const std::string& fmt, const std::locale& loc);
105 template<typename value_t>
106 inline std::string to_string(value_t* const value, const std::string& fmt, const std::locale& loc);
107 template<typename type_t>
108 inline std::string to_string(const std::shared_ptr<type_t>& value, const std::string& fmt, const std::locale& loc);
109 template<typename type_t>
110 inline std::string to_string(const std::unique_ptr<type_t>& value, const std::string& fmt, const std::locale& loc);
111 template<>
112 inline std::string to_string(const std::any& value, const std::string& fmt, const std::locale& loc);
113 template<typename types_t>
114 inline std::string to_string(const std::optional<types_t>& value, const std::string& fmt, const std::locale& loc);
115 template<>
116 inline std::string to_string(const std::nullopt_t& value, const std::string& fmt, const std::locale& loc);
117 template<typename type1_t, typename type2_t>
118 inline std::string to_string(const std::pair<type1_t, type2_t>& value, const std::string& fmt, const std::locale& loc);
119 template<typename ... types_t>
120 inline std::string to_string(const std::tuple<types_t ...>& value, const std::string& fmt, const std::locale& loc);
121 template<typename type_t, size_t size>
122 inline std::string to_string(const std::array<type_t, size>& values, const std::string& fmt, const std::locale& loc);
123 template<typename type_t, typename allocator_t = std::allocator<type_t>>
124 inline std::string to_string(const std::deque<type_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
125 template<typename type_t, typename allocator_t = std::allocator<type_t>>
126 inline std::string to_string(const std::forward_list<type_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
127 template<typename type_t>
128 inline std::string to_string(const std::initializer_list<type_t>& values, const std::string& fmt, const std::locale& loc);
129 template<typename type_t, typename allocator_t = std::allocator<type_t>>
130 inline std::string to_string(const std::list<type_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
131 template<typename type_t>
132 inline std::string to_string(const std::valarray<type_t>& values, const std::string& fmt, const std::locale& loc);
133 template<typename type_t, typename allocator_t = std::allocator<type_t>>
134 inline std::string to_string(const std::vector<type_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
135 template<typename key_t, typename value_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<std::pair<const key_t, value_t>>>
136 inline std::string to_string(const std::map<key_t, value_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
137 template<typename key_t, typename value_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<std::pair<const key_t, value_t>>>
138 inline std::string to_string(const std::multimap<key_t, value_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
139 template<typename key_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<key_t>>
140 inline std::string to_string(const std::multiset<key_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
141 template<typename key_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<key_t>>
142 inline std::string to_string(const std::set<key_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
143 template<typename key_t, typename value_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<std::pair<const key_t, value_t>>>
144 inline std::string to_string(const std::unordered_map<key_t, value_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
145 template<typename key_t, typename value_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<std::pair<const key_t, value_t>>>
146 inline std::string to_string(const std::unordered_multimap<key_t, value_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
147 template<typename key_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<key_t>>
148 inline std::string to_string(const std::unordered_multiset<key_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
149 template<typename key_t, typename compare_t = std::less<key_t>, typename allocator_t = std::allocator<key_t>>
150 inline std::string to_string(const std::unordered_set<key_t, compare_t, allocator_t>& values, const std::string& fmt, const std::locale& loc);
151 template<typename type_t>
152 inline std::string to_string(const xtd::collections::generic::ienumerable<type_t>& values, const std::string& fmt, const std::locale& loc);
153
154 template<typename value_t>
155 inline std::wstring to_string(const value_t& value, const std::wstring& fmt, const std::locale& loc);
156 template<>
157 inline std::wstring to_string(const bool& value, const std::wstring& fmt, const std::locale& loc);
158 template<>
159 inline std::wstring to_string(const xtd::sbyte& value, const std::wstring& fmt, const std::locale& loc);
160 template<>
161 inline std::wstring to_string(const char& value, const std::wstring& fmt, const std::locale& loc);
162 template<>
163 inline std::wstring to_string(const unsigned char& value, const std::wstring& fmt, const std::locale& loc);
164 template<>
165 inline std::wstring to_string(const short& value, const std::wstring& fmt, const std::locale& loc);
166 template<>
167 inline std::wstring to_string(const unsigned short& value, const std::wstring& fmt, const std::locale& loc);
168 template<>
169 inline std::wstring to_string(const int& value, const std::wstring& fmt, const std::locale& loc);
170 template<>
171 inline std::wstring to_string(const unsigned int& value, const std::wstring& fmt, const std::locale& loc);
172 template<>
173 inline std::wstring to_string(const long& value, const std::wstring& fmt, const std::locale& loc);
174 template<>
175 inline std::wstring to_string(const unsigned long& value, const std::wstring& fmt, const std::locale& loc);
176 template<>
177 inline std::wstring to_string(const long long& value, const std::wstring& fmt, const std::locale& loc);
178 template<>
179 inline std::wstring to_string(const unsigned long long& value, const std::wstring& fmt, const std::locale& loc);
180 template<>
181 inline std::wstring to_string(const float& value, const std::wstring& fmt, const std::locale& loc);
182 template<>
183 inline std::wstring to_string(const double& value, const std::wstring& fmt, const std::locale& loc);
184 template<>
185 inline std::wstring to_string(const long double& value, const std::wstring& fmt, const std::locale& loc);
186 template<>
187 inline std::wstring to_string(const std::chrono::system_clock::time_point& value, const std::wstring& fmt, const std::locale& loc);
188 template<>
189 inline std::wstring to_string(const std::tm& value, const std::wstring& fmt, const std::locale& loc);
190
191 template<typename type_t, typename period_t = std::ratio<1>>
192 inline std::wstring to_string(const std::chrono::duration<type_t, period_t>& value, const std::wstring& fmt, const std::locale& loc);
193#if defined(__xtd__cpp_lib_char8_t)
194 template<>
195 inline std::wstring to_string(const xtd::char8& value, const std::wstring& fmt, const std::locale& loc);
196#endif
197 template<>
198 inline std::wstring to_string(const xtd::char16& value, const std::wstring& fmt, const std::locale& loc);
199 template<>
200 inline std::wstring to_string(const xtd::char32& value, const std::wstring& fmt, const std::locale& loc);
201 template<>
202 inline std::wstring to_string(const xtd::wchar& value, const std::wstring& fmt, const std::locale& loc);
203
204 template<typename type_t, typename string_t>
205 inline string_t to_string(type_t value, const std::map<type_t, string_t, std::greater<type_t>>& values) {
206 auto it = values.find(value);
207 if (it != values.end()) return it->second;
208 string_t result;
209 long long rest = static_cast<long long>(value);
210 for (auto item : values) {
211 if (static_cast<long long>(item.first) != 0 && (rest & static_cast<long long>(item.first)) == static_cast<long long>(item.first)) {
212 if (!result.empty()) result = string_t {',', ' '} + result;
213 result = item.second + result;
214 rest -= static_cast<long long>(item.first);
215 }
216 }
217 if (!result.empty()) return result;
218 return to_string(static_cast<long long>(value), string_t {'G'}, std::locale());
219 }
220
221 template<typename type_t, typename string_t>
222 inline string_t to_string(type_t value, const std::map<type_t, string_t>& values) {
223 std::map<type_t, string_t, std::greater<type_t>> descending_values;
224 for (auto item : values) descending_values[item.first] = item.second;
225 return to_string(value, descending_values);
226 }
227
228 template<typename type_t>
229 inline std::string to_string(type_t value, const std::initializer_list<std::pair<type_t, std::string>>& il) {
230 std::map<type_t, std::string, std::greater<type_t>> values;
231 for (auto item : il) values[item.first] = item.second;
232 return to_string(value, values);
233 }
234
235 template<typename type_t>
236 inline std::wstring to_string(type_t value, const std::initializer_list<std::pair<type_t, std::wstring>>& il) {
237 std::map<type_t, std::wstring, std::greater<type_t>> values;
238 for (auto item : il) values[item.first] = item.second;
239 return to_string(value, values);
240 }
241}
242
243template<typename char_t>
244inline std::basic_string<char_t> __codepoint_to_string(xtd::char32 codepoint) {
245 std::basic_string<char_t> result;
246 if (codepoint < 0x80)
247 result.push_back(static_cast<char_t>(codepoint));
248 else if (codepoint < 0x800) {
249 result.push_back(static_cast<char_t>((codepoint >> 6) | 0xc0));
250 result.push_back(static_cast<char_t>((codepoint & 0x3f) | 0x80));
251 } else if (codepoint < 0x10000) {
252 result.push_back(static_cast<char_t>((codepoint >> 12) | 0xe0));
253 result.push_back(static_cast<char_t>(((codepoint >> 6) & 0x3f) | 0x80));
254 result.push_back(static_cast<char_t>((codepoint & 0x3f) | 0x80));
255 } else {
256 result.push_back(static_cast<char_t>((codepoint >> 18) | 0xf0));
257 result.push_back(static_cast<char_t>(((codepoint >> 12) & 0x3f) | 0x80));
258 result.push_back(static_cast<char_t>(((codepoint >> 6) & 0x3f) | 0x80));
259 result.push_back(static_cast<char_t>((codepoint & 0x3f) | 0x80));
260 }
261 return result;
262}
263
264template<typename char_t>
265inline std::basic_string<char_t> __to_string(char codepoint) {
266 return __codepoint_to_string<char_t>(codepoint);
267}
268
269template<typename char_t>
270inline std::basic_string<char_t> __to_string(xtd::char32 codepoint) {
271 return __codepoint_to_string<char_t>(codepoint);
272}
273
274template<typename char_t>
275inline std::basic_string<char_t> __to_string(xtd::char16 codepoint) {
276 return __codepoint_to_string<char_t>(codepoint);
277}
278
279#if defined(__xtd__cpp_lib_char8_t)
280template<typename char_t>
281inline std::basic_string<char_t> __to_string(xtd::char8 codepoint) {
282 return __codepoint_to_string<char_t>(codepoint);
283}
284#endif
285
286template<typename char_t>
287inline std::basic_string<char_t> __to_string(xtd::wchar codepoint) {
288 return __codepoint_to_string<char_t>(codepoint);
289}
290
291template<typename char_t>
292inline std::basic_string<char_t> __to_string(const std::basic_string<char_t>& str) {
293 std::basic_string<char_t> result;
294 std::for_each(str.begin(), str.end(), [&](auto codepoint) {result += __to_string<char_t>(codepoint);});
295 return result;
296}
297
298template<typename char_t, typename arg_t>
299inline std::basic_string<char_t> __to_string(const std::basic_string<arg_t>& str) {
300 std::basic_string<char_t> result;
301 for (auto codepoint : str)
302 result += __to_string<char_t>(codepoint);
303 return result;
304}
305
306template<typename char_t, typename arg_t>
307inline std::basic_string<char_t> __to_string(const arg_t* str) {
308 std::basic_string<char_t> result;
309 for (auto codepoint : std::basic_string<arg_t>(str))
310 result += __to_string<char_t>(codepoint);
311 return result;
312}
313
314template<typename char_t, typename type_t, typename period_t = std::ratio<1>>
315std::basic_ostream<char_t>& operator <<(std::basic_ostream<char_t>& os, const std::chrono::duration<type_t, period_t>& value) {
316 return os << xtd::to_string(value, std::basic_string<char_t> {'G'}, std::locale());
317}
318
319#if defined(__xtd__cpp_lib_char8_t)
320std::ostream& operator <<(std::ostream& os, const xtd::char8* str);
321#endif
322std::ostream& operator <<(std::ostream& os, const xtd::char16* str);
323std::ostream& operator <<(std::ostream& os, const xtd::char32* str);
324std::ostream& operator <<(std::ostream& os, const xtd::wchar* str);
325
326template<typename enum_t>
327std::string __enum_to_string(enum_t value) noexcept;
328std::string __iformatable_to_string(const xtd::iformatable& value) noexcept;
329std::string __object_to_string(const xtd::object& value) noexcept;
330
331template <typename char_t, typename type_t, typename bool_t>
332struct __enum_ostream__ {};
333
334template <typename char_t, typename type_t>
335struct __enum_ostream__<char_t, type_t, std::true_type> {
336 std::basic_ostream<char_t>& to_stream(std::basic_ostream<char_t>& os, const type_t& value) noexcept {
337 return os << __enum_to_string(value);
338 }
339};
340
341template <typename char_t, typename type_t>
342struct __enum_ostream__<char_t, type_t, std::false_type> {
343 std::basic_ostream<char_t>& to_stream(std::basic_ostream<char_t>& os, const type_t& value) noexcept {
344 //return os << value;
345 return os << xtd::to_string(value, std::basic_string<char_t> {}, std::locale {});
346 }
347};
348
349template <typename char_t, typename type_t, typename bool_t>
350struct __enum_or_polymorphic_ostream__ {};
351
352template <typename char_t, typename type_t>
353struct __enum_or_polymorphic_ostream__<char_t, type_t, std::true_type> {
354 std::basic_ostream<char_t>& to_stream(std::basic_ostream<char_t>& os, const type_t& value) noexcept {
355 if (dynamic_cast<const xtd::iformatable*>(&value)) return os << __iformatable_to_string(dynamic_cast<const xtd::iformatable&>(value));
356 if (dynamic_cast<const xtd::object*>(&value)) return os << __object_to_string(dynamic_cast<const xtd::object&>(value));
357 return os << value;
358 }
359};
360
361template <typename char_t, typename type_t>
362struct __enum_or_polymorphic_ostream__<char_t, type_t, std::false_type> {
363 std::basic_ostream<char_t>& to_stream(std::basic_ostream<char_t>& os, const type_t& value) noexcept {
364 __enum_ostream__<char, type_t, typename std::is_enum<type_t>::type>().to_stream(os, value);
365 return os;
366 }
367};
368
369template<typename value_t>
370std::string __format_stringer_to_std_string(const value_t& value) {
371 std::basic_stringstream<char> ss;
372 //ss << value;
373 __enum_or_polymorphic_ostream__<char, value_t, typename std::is_polymorphic<value_t>::type>().to_stream(ss, value);
374 return ss.str();
375}
376
377std::string __format_stringer_to_std_string(const char& c);
378#if defined(__xtd__cpp_lib_char8_t)
379std::string __format_stringer_to_std_string(const xtd::char8& c);
380#endif
381std::string __format_stringer_to_std_string(const xtd::char16& c);
382std::string __format_stringer_to_std_string(const xtd::char32& c);
383std::string __format_stringer_to_std_string(const xtd::wchar& c);
384std::string __format_stringer_to_std_string(const char* str);
385#if defined(__xtd__cpp_lib_char8_t)
386std::string __format_stringer_to_std_string(const xtd::char8* str);
387#endif
388std::string __format_stringer_to_std_string(const xtd::char16* str);
389std::string __format_stringer_to_std_string(const xtd::char32* str);
390std::string __format_stringer_to_std_string(const xtd::wchar* str);
391std::string __format_stringer_to_std_string(const std::string& str);
392std::string __format_stringer_to_std_string(const xtd::string& str);
393#if defined(__xtd__cpp_lib_char8_t)
394std::string __format_stringer_to_std_string(const std::u8string& str);
395#endif
396std::string __format_stringer_to_std_string(const std::u16string& str);
397std::string __format_stringer_to_std_string(const std::u32string& str);
398std::string __format_stringer_to_std_string(const std::wstring& str);
399
400template<typename char_t, typename value_t>
401inline std::basic_string<char_t> __format_stringer(value_t value) {
402 std::basic_stringstream<char_t> ss;
403 ss << __format_stringer_to_std_string(value).c_str(); // Using "c_str()" is not the best method, but it is the only possibility if "char_t" is of another type than "char".
404 return ss.str();
405}
406
407template<typename char_t, typename value_t>
408inline std::basic_string<char_t> __format_stringer(const bool& value) {
409 std::basic_stringstream<char_t> ss;
410 ss << std::boolalpha << value;
411 return ss.str();
412}
413
414template<typename char_t, typename value_t, xtd::int32 len>
415inline std::basic_string<char_t> __format_stringer(const char*& value) {
416 std::basic_stringstream<char_t> ss;
417 ss << __to_string<char_t>(value);
418 return ss.str();
419}
420
421template<typename char_t, typename value_t, xtd::int32 len>
422inline std::basic_string<char_t> __format_stringer(const char* const& value) {
423 std::basic_stringstream<char_t> ss;
424 ss << __to_string<char_t>(value);
425 return ss.str();
426}
427
428#if defined(__xtd__cpp_lib_char8_t)
429template<typename char_t, typename value_t>
430inline std::basic_string<char_t> __format_stringer(const xtd::char8*& value) {
431 auto s = std::u8string(value);
432 std::basic_stringstream<char_t> ss;
433 ss << std::basic_string<char_t>(s.begin(), s.end());
434 return ss.str();
435}
436
437template<typename char_t, typename value_t>
438inline std::basic_string<char_t> __format_stringer(const xtd::char8* const& value) {
439 auto s = std::u8string(value);
440 std::basic_stringstream<char_t> ss;
441 ss << std::basic_string<char_t>(s.begin(), s.end());
442 return ss.str();
443}
444#endif
445
446template<typename char_t, typename value_t>
447inline std::basic_string<char_t> __format_stringer(const xtd::char16*& value) {
448 std::basic_stringstream<char_t> ss;
449 ss << __to_string<char_t>(value);
450 return ss.str();
451}
452
453template<typename char_t, typename value_t>
454inline std::basic_string<char_t> __format_stringer(const xtd::char16* const& value) {
455 std::basic_stringstream<char_t> ss;
456 ss << __to_string<char_t>(value);
457 return ss.str();
458}
459
460template<typename char_t, typename value_t>
461inline std::basic_string<char_t> __format_stringer(const xtd::char32*& value) {
462 std::basic_stringstream<char_t> ss;
463 ss << __to_string<char_t>(value);
464 return ss.str();
465}
466
467template<typename char_t, typename value_t>
468inline std::basic_string<char_t> __format_stringer(const xtd::char32* const& value) {
469 std::basic_stringstream<char_t> ss;
470 ss << __to_string<char_t>(value);
471 return ss.str();
472}
473
474template<typename char_t, typename value_t>
475inline std::basic_string<char_t> __format_stringer(const xtd::wchar*& value) {
476 std::basic_stringstream<char_t> ss;
477 ss << __to_string<char_t>(value);
478 return ss.str();
479}
480
481template<typename char_t, typename value_t>
482inline std::basic_string<char_t> __format_stringer(const xtd::wchar* const& value) {
483 std::basic_stringstream<char_t> ss;
484 ss << __to_string<char_t>(value);
485 return ss.str();
486}
487
488#if defined(__xtd__cpp_lib_char8_t)
489template<>
490inline std::string __format_stringer<char, std::u8string&>(std::u8string& value) {
491 std::basic_stringstream<char> ss;
492 ss << std::string(value.begin(), value.end());
493 return ss.str();
494}
495#endif
496
497template<>
498inline std::string __format_stringer<char, const std::u16string&>(const std::u16string& value) {
499 std::basic_stringstream<char> ss;
500 ss << __to_string<char>(value);
501 return ss.str();
502}
503
504template<>
505inline std::string __format_stringer<char, const std::u32string&>(const std::u32string& value) {
506 std::basic_stringstream<char> ss;
507 ss << __to_string<char>(value);
508 return ss.str();
509}
510
511template<>
512inline std::string __format_stringer<char, const std::wstring&>(const std::wstring& value) {
513 std::basic_stringstream<char> ss;
514 ss << __to_string<char>(value);
515 return ss.str();
516}
517
518template<>
519inline std::string __format_stringer<char, bool&>(bool& value) {
520 return xtd::to_string(value, "G", std::locale());
521}
522
523template<>
524inline std::string __format_stringer<char, xtd::sbyte&>(xtd::sbyte& value) {
525 return xtd::to_string(value, "G", std::locale());
526}
527
528template<>
529inline std::string __format_stringer<char, const unsigned char&>(const unsigned char& value) {
530 return xtd::to_string(value, "G", std::locale());
531}
532
533template<>
534inline std::string __format_stringer<char, unsigned char&>(unsigned char& value) {
535 return xtd::to_string(value, "G", std::locale());
536}
537
538template<>
539inline std::string __format_stringer<char, short&>(short& value) {
540 return xtd::to_string(value, "G", std::locale());
541}
542
543template<>
544inline std::string __format_stringer<char, unsigned short&>(unsigned short& value) {
545 return xtd::to_string(value, "G", std::locale());
546}
547
548template<>
549inline std::string __format_stringer<char, int&>(int& value) {
550 return xtd::to_string(value, "G", std::locale());
551}
552
553template<>
554inline std::string __format_stringer<char, unsigned int&>(unsigned int& value) {
555 return xtd::to_string(value, "G", std::locale());
556}
557
558template<>
559inline std::string __format_stringer<char, long&>(long& value) {
560 return xtd::to_string(value, "G", std::locale());
561}
562
563template<>
564inline std::string __format_stringer<char, unsigned long&>(unsigned long& value) {
565 return xtd::to_string(value, "G", std::locale());
566}
567
568template<>
569inline std::string __format_stringer<char, long long&>(long long& value) {
570 return xtd::to_string(value, "G", std::locale());
571}
572
573template<>
574inline std::string __format_stringer<char, unsigned long long&>(unsigned long long& value) {
575 return xtd::to_string(value, "G", std::locale());
576}
577
578template<>
579inline std::string __format_stringer<char, float&>(float& value) {
580 return xtd::to_string(value, "G", std::locale());
581}
582
583template<>
584inline std::string __format_stringer<char, double&>(double& value) {
585 return xtd::to_string(value, "G", std::locale());
586}
587
588template<>
589inline std::string __format_stringer<char, long double&>(long double& value) {
590 return xtd::to_string(value, "G", std::locale());
591}
592
593template<>
594inline std::string __format_stringer<char, std::chrono::system_clock::time_point&> (std::chrono::system_clock::time_point& value) {
595 return xtd::to_string(value, "G", std::locale());
596}
597
598template<>
599inline std::string __format_stringer<char, std::tm&> (tm& value) {
600 return xtd::to_string(value, "G", std::locale());
601}
602
603template<>
604inline std::string __format_stringer<char, xtd::wchar&>(xtd::wchar& value) {
605 return xtd::to_string(value, "G", std::locale());
606}
607
608#if defined(__xtd__cpp_lib_char8_t)
609template<>
610inline std::string __format_stringer<char, xtd::char8&>(xtd::char8& value) {
611 return xtd::to_string(value, "G", std::locale());
612}
613#endif
614
615template<>
616inline std::string __format_stringer<char, xtd::char16&>(xtd::char16& value) {
617 return xtd::to_string(value, "G", std::locale());
618}
619
620template<>
621inline std::string __format_stringer<char, xtd::char32&>(xtd::char32& value) {
622 return xtd::to_string(value, "G", std::locale());
623}
624
625#if defined(__xtd__cpp_lib_char8_t)
626template<>
627inline std::wstring __format_stringer<xtd::wchar, std::u8string&>(std::u8string& value) {
628 std::basic_stringstream<xtd::wchar> ss;
629 ss << std::wstring(value.begin(), value.end());
630 return ss.str();
631}
632#endif
633
634template<>
635inline std::wstring __format_stringer<xtd::wchar, const std::u16string&>(const std::u16string& value) {
636 std::basic_stringstream<xtd::wchar> ss;
637 ss << __to_string<xtd::wchar>(value);
638 return ss.str();
639}
640
641template<>
642inline std::wstring __format_stringer<xtd::wchar, const std::u32string&>(const std::u32string& value) {
643 std::basic_stringstream<xtd::wchar> ss;
644 ss << __to_string<xtd::wchar>(value);
645 return ss.str();
646}
647
648template<>
649inline std::wstring __format_stringer<xtd::wchar, const std::string&>(const std::string& value) {
650 std::basic_stringstream<xtd::wchar> ss;
651 ss << __to_string<xtd::wchar>(value);
652 return ss.str();
653}
654
655template<>
656inline std::wstring __format_stringer<xtd::wchar, bool&>(bool& value) {
657 return xtd::to_string(value, L"G", std::locale());
658}
659
660template<>
661inline std::wstring __format_stringer<xtd::wchar, xtd::sbyte&>(xtd::sbyte& value) {
662 return xtd::to_string(value, L"G", std::locale());
663}
664
665template<>
666inline std::wstring __format_stringer<xtd::wchar, char&>(char& value) {
667 return xtd::to_string(value, L"G", std::locale());
668}
669
670template<>
671inline std::wstring __format_stringer<xtd::wchar, unsigned char&>(unsigned char& value) {
672 return xtd::to_string(value, L"G", std::locale());
673}
674
675template<>
676inline std::wstring __format_stringer<xtd::wchar, short&>(short& value) {
677 return xtd::to_string(value, L"G", std::locale());
678}
679
680template<>
681inline std::wstring __format_stringer<xtd::wchar, unsigned short&>(unsigned short& value) {
682 return xtd::to_string(value, L"G", std::locale());
683}
684
685template<>
686inline std::wstring __format_stringer<xtd::wchar, int&>(int& value) {
687 return xtd::to_string(value, L"G", std::locale());
688}
689
690template<>
691inline std::wstring __format_stringer<xtd::wchar, unsigned int&>(unsigned int& value) {
692 return xtd::to_string(value, L"G", std::locale());
693}
694
695template<>
696inline std::wstring __format_stringer<xtd::wchar, long&>(long& value) {
697 return xtd::to_string(value, L"G", std::locale());
698}
699
700template<>
701inline std::wstring __format_stringer<xtd::wchar, unsigned long&>(unsigned long& value) {
702 return xtd::to_string(value, L"G", std::locale());
703}
704
705template<>
706inline std::wstring __format_stringer<xtd::wchar, long long&>(long long& value) {
707 return xtd::to_string(value, L"G", std::locale());
708}
709
710template<>
711inline std::wstring __format_stringer<xtd::wchar, unsigned long long&>(unsigned long long& value) {
712 return xtd::to_string(value, L"G", std::locale());
713}
714
715template<>
716inline std::wstring __format_stringer<xtd::wchar, float&>(float& value) {
717 return xtd::to_string(value, L"G", std::locale());
718}
719
720template<>
721inline std::wstring __format_stringer<xtd::wchar, double&>(double& value) {
722 return xtd::to_string(value, L"G", std::locale());
723}
724
725template<>
726inline std::wstring __format_stringer<xtd::wchar, long double&>(long double& value) {
727 return xtd::to_string(value, L"G", std::locale());
728}
729
730template<>
731inline std::wstring __format_stringer<xtd::wchar, std::chrono::system_clock::time_point&> (std::chrono::system_clock::time_point& value) {
732 return xtd::to_string(value, L"G", std::locale());
733}
734
735template<>
736inline std::wstring __format_stringer<xtd::wchar, std::tm&> (tm& value) {
737 return xtd::to_string(value, L"G", std::locale());
738}
Contains string definitions.
Contains __xtd_std_version definitions.
Represents text as a sequence of character units.
Definition basic_string.hpp:79
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
Provides functionality to format the value of an object into a string representation.
Definition iformatable.hpp:35
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:27
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
char16_t char16
Represents a 16-bit unicode character.
Definition char16.hpp:26
char32_t char32
Represents a 32-bit unicode character.
Definition char32.hpp:26
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition to_string.hpp:41
@ s
The S key.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10