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