6#if !defined(__XTD_TO_STRING_INTERNAL__)
7#error "Do not include this file: Internal use only. Include <xtd/to_string> or <xtd/to_string.hpp> instead."
15template<
class value_t>
17 return __to_string_polymorphic(value, fmt, loc, std::is_polymorphic<value_t>());
22 return __boolean_formatter(fmt.chars(), value, loc);
27 return __numeric_formatter(fmt.chars(), value, loc);
32 return __character_formatter(fmt.chars(), value, loc);
37 return __numeric_formatter(fmt.chars(), value, loc);
42 return __numeric_formatter(fmt.chars(), value, loc);
47 return __numeric_formatter(fmt.chars(), value, loc);
52 return __numeric_formatter(fmt.chars(), value, loc);
57 return __numeric_formatter(fmt.chars(), value, loc);
62 return __numeric_formatter(fmt.chars(), value, loc);
67 return __numeric_formatter(fmt.chars(), value, loc);
72 return __numeric_formatter(fmt.chars(), value, loc);
77 return __numeric_formatter(fmt.chars(), value, loc);
82 return __floating_point_formatter(fmt.chars(), value, loc);
87 return __floating_point_formatter(fmt.chars(), value, loc);
92 return __floating_point_formatter(fmt.chars(), value, loc);
97 return __date_time_formatter(fmt.chars(), std::chrono::system_clock::to_time_t(value), std::chrono::duration_cast<std::chrono::nanoseconds>(value.time_since_epoch()).
count() % 1000000000, loc);
102 return __date_time_formatter(fmt.chars(), value, 0, loc);
105template<
class type_t,
class period_t>
107 return __duration_formatter(fmt.chars(), value, loc);
112 return __character_formatter(fmt.chars(), value, loc);
117 return __character_formatter(fmt.chars(), value, loc);
122 return __character_formatter(fmt.chars(), value, loc);
127 return __character_formatter(fmt.chars(), value, loc);
130template<
class value_t>
132 return to_string(value, fmt, std::locale());
136 return to_string(value, fmt, std::locale());
141 if (value == std::partial_ordering::less)
return "less";
142 if (value == std::partial_ordering::greater)
return "greater";
148 if (value == std::strong_ordering::less)
return "less";
149 if (value == std::strong_ordering::greater)
return "greater";
155 if (value == std::weak_ordering::less)
return "less";
156 if (value == std::weak_ordering::greater)
return "greater";
160template<
class value_t>
162 if (!value)
return "(null)";
163 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(value), loc);
166template<
class value_t>
168 if (!value)
return "(null)";
169 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(value), loc);
172template<
class type_t>
174 if (!value)
return "(null)";
175 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(value.get()), loc);
178template<
class type_t>
180 if (!value)
return "(null)";
181 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(value.get()), loc);
186 auto iterator = __any_stringer__.
find(std::type_index(value.type()));
187 return iterator != __any_stringer__.cend() ?
xtd::to_string(iterator->second(value), fmt, loc) :
"(unregistered)";
190template<
class type_t>
192 return !value.has_value() ?
"(null)" : std::string {
"("} +
to_string(value.value(), fmt, loc).chars() + std::string {
")"};
205template<
class type1_t,
class type2_t>
207 return std::string {
"("} +
to_string(value.first, fmt, loc).chars() + std::string {
", "} +
to_string(value.second, fmt, loc).chars() + std::string {
")"};
210template<
class type_t,
unsigned n_t,
unsigned last_t>
211inline xtd::string xtd::__xtd_tuple_stringer<type_t, n_t, last_t>::to_string(
const std::string& str,
const type_t& value,
const xtd::string& fmt,
const std::locale& loc) {
212 return __xtd_tuple_stringer < type_t, n_t + 1, last_t >::to_string(str +
xtd::to_string(std::get<n_t>(value), fmt, loc).chars() +
", ", value, fmt, loc);
215template<
class type_t,
unsigned n_t>
216inline xtd::string xtd::__xtd_tuple_stringer<type_t, n_t, n_t>::to_string(
const std::string& str,
const type_t& value,
const xtd::string& fmt,
const std::locale& loc) {
217 return str +
xtd::to_string(std::get<n_t>(value), fmt, loc).chars();
220template<
class ...types_t>
222 return __xtd_tuple_stringer < std::tuple<types_t ...>, 0,
sizeof...(types_t) - 1 >::to_string(std::string {
"("}, value, fmt, loc) +
")";
225template<
class iterator_t>
226inline std::string __xtd_iterator_to_string(
const std::string& str, iterator_t iterator,
const iterator_t& begin,
const iterator_t& end,
const xtd::string& fmt,
const std::locale& loc) {
227 if (iterator == end)
return str;
228 auto new_str = str + (iterator ==
begin ? std::string {} : std::string {
", "}) +
xtd::to_string(*iterator, fmt, loc).chars();
229 return __xtd_iterator_to_string(new_str, ++iterator, begin, end, fmt, loc);
232template<
class iterator_t>
233inline std::string __xtd_sequence_container_to_string(
const iterator_t& begin,
const iterator_t& end,
const xtd::string& fmt,
const std::locale& loc) {
234 return __xtd_iterator_to_string(
"[", begin, begin, end, fmt, loc) +
"]";
237template<
class type_t,
size_t size>
239 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
242template<
class type_t,
class allocator_t>
244 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
247template<
class type_t,
class allocator_t>
249 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
252template<
class type_t>
254 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
257template<
class type_t,
class allocator_t>
259 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
262template<
class type_t>
264 return __xtd_sequence_container_to_string(std::begin(values), std::end(values), fmt, loc);
267template<
class type_t,
class allocator_t>
269 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
272template<
class iterator_t>
273inline std::string __xtd_associative_container_to_string(
const iterator_t& begin,
const iterator_t& end,
const xtd::string& fmt,
const std::locale& loc) {
274 return __xtd_iterator_to_string(
"{", begin, begin, end, fmt, loc) +
"}";
277template<
class key_t,
class value_t,
class compare_t,
class allocator_t>
279 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
282template<
class key_t,
class value_t,
class compare_t,
class allocator_t>
284 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
287template<
class key_t,
class compare_t,
class allocator_t>
289 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
292template<
class key_t,
class compare_t,
class allocator_t>
294 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
297template<
class key_t,
class value_t,
class compare_t,
class allocator_t>
299 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
302template<
class key_t,
class value_t,
class compare_t,
class allocator_t>
304 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
307template<
class key_t,
class compare_t,
class allocator_t>
309 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
312template<
class key_t,
class compare_t,
class allocator_t>
314 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
317template<
class type_t>
319 std::map<type_t, xtd::string, std::greater<type_t>> values;
320 for (
auto item : il) values[item.first] = item.second;
324#if defined(__xtd__cpp_lib_ranges)
348template<
class type_t>
350 return __xtd_sequence_container_to_string(values.
begin(), values.
end(), fmt, loc);
353template<
class type_t>
355 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
358template<
class type_t,
class string_t>
359inline string_t
xtd::to_string(type_t value,
const std::map<type_t, string_t, std::greater<type_t>>& values) {
360 auto it = values.find(value);
361 if (it != values.end())
return it->second;
363 long long rest =
static_cast<long long>(value);
364 for (
auto item : values) {
365 if (
static_cast<long long>(item.first) != 0 && (rest &
static_cast<long long>(item.first)) ==
static_cast<long long>(item.first)) {
366 if (!result.empty()) result = string_t {
',',
' '} + result;
367 result = item.second + result;
368 rest -=
static_cast<long long>(item.first);
371 if (!result.empty())
return result;
372 return to_string(
static_cast<long long>(value), string_t {
'G'}, std::locale());
375template<
class type_t,
class string_t>
376inline string_t
xtd::to_string(type_t value,
const std::map<type_t, string_t>& values) {
377 std::map<type_t, string_t, std::greater<type_t>> descending_values;
378 for (
auto item : values) descending_values[item.first] = item.second;
379 return to_string(value, descending_values);
382template<
class char_t,
class value_t>
383inline std::basic_string<char_t> __string_formatter(
const std::basic_string<char_t>& fmt, value_t value,
const std::locale& loc) {
384 return __format_stringer<char_t>(value);
388inline std::string __format_stringer < char, bool& > (
bool& value) {
393inline std::string __format_stringer < char, xtd::sbyte& > (
xtd::sbyte& value) {
398inline std::string __format_stringer < char, const unsigned char& > (
const unsigned char& value) {
403inline std::string __format_stringer < char, unsigned char& > (
unsigned char& value) {
408inline std::string __format_stringer < char, short& > (
short& value) {
413inline std::string __format_stringer < char, unsigned short& > (
unsigned short& value) {
418inline std::string __format_stringer < char, int& > (
int& value) {
423inline std::string __format_stringer < char, unsigned int& > (
unsigned int& value) {
428inline std::string __format_stringer < char, long& > (
long& value) {
433inline std::string __format_stringer < char, unsigned long& > (
unsigned long& value) {
438inline std::string __format_stringer < char, long long& > (
long long& value) {
443inline std::string __format_stringer < char, unsigned long long& > (
unsigned long long& value) {
448inline std::string __format_stringer < char, float& > (
float& value) {
453inline std::string __format_stringer < char, double& > (
double& value) {
458inline std::string __format_stringer < char, long double& > (
long double& value) {
463inline std::string __format_stringer < char, std::chrono::system_clock::time_point& > (std::chrono::system_clock::time_point& value) {
468inline std::string __format_stringer < char, std::tm& > (tm& value) {
473inline std::string __format_stringer < char, xtd::wchar& > (
xtd::wchar& value) {
478inline std::string __format_stringer < char, xtd::char8& > (
xtd::char8& value) {
483inline std::string __format_stringer < char, xtd::char16& > (
xtd::char16& value) {
488inline std::string __format_stringer < char, xtd::char32& > (
xtd::char32& value) {
492template<
class char_t,
class type_t,
class period_t = std::ratio<1>>
493std::basic_ostream<char_t>& operator <<(std::basic_ostream<char_t>& os,
const std::chrono::duration<type_t, period_t>& value) {
494 return os <<
xtd::to_string(value, std::basic_string<char_t> {
'G'}, std::locale());
497template <
class char_t,
class type_t >
498struct __enum_ostream__ < char_t, type_t, std::false_type > {
499 std::basic_ostream < char_t >& to_stream(std::basic_ostream < char_t >& os,
const type_t& value)
noexcept {
501 return os <<
xtd::to_string(value, std::basic_string < char_t > {}, std::locale {});
size_type find(const basic_string &str) const
Finds the first substring equal to the given character sequence. Search begins at 0,...
Definition basic_string.hpp:1129
virtual const_iterator begin() const
Returns an iterator to the first element of the enumerable.
Definition enumerable_iterators.hpp:141
virtual const_iterator end() const
Returns an iterator to the element following the last element of the enumerable.
Definition enumerable_iterators.hpp:156
size_t count() const noexcept
Returns the number of elements in current sequence.
Definition enumerable.hpp:209
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
char8_t char8
Represents a 8-bit unicode character.
Definition char8.hpp:26
std::int8_t sbyte
Represents a 8-bit signed integer.
Definition sbyte.hpp:23
wchar_t wchar
Represents a wide character.
Definition wchar.hpp:24
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.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:23
std::any any
Represents the any alias on std::any.
Definition any.hpp:24
const_iterator begin() const
Returns an iterator to the beginning.
Definition read_only_span.hpp:183
string to_string() const noexcept override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:375
Contains xtd::to_string methods.