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."
16template<xtd::iterable range_t>
17[[nodiscard]]
auto __xtd_iterable_to_string(
const range_t& values,
const xtd::string& fmt,
const std::locale& loc) -> std::string;
19template<
typename value_t>
21 if constexpr(std::is_polymorphic_v<value_t>)
return __to_string_polymorphic(value, fmt, loc);
22 else if constexpr(std::is_enum_v<value_t>)
return __enum_formatter<char>(fmt, value, loc);
25 else if constexpr(
xtd::iterable<value_t> && !std::is_same_v<value_t, xtd::string>)
return __xtd_iterable_to_string(value, fmt, loc);
27 auto ss = std::stringstream {};
49 return __boolean_formatter(fmt.chars(), value, loc);
54 return __numeric_formatter(fmt.chars(), value, loc);
59 return __character_formatter(fmt.chars(), value, loc);
64 return __numeric_formatter(fmt.chars(), value, loc);
69 return __numeric_formatter(fmt.chars(), value, loc);
74 return __numeric_formatter(fmt.chars(), value, loc);
79 return __numeric_formatter(fmt.chars(), value, loc);
84 return __numeric_formatter(fmt.chars(), value, loc);
89 return __numeric_formatter(fmt.chars(), value, loc);
94 return __numeric_formatter(fmt.chars(), value, loc);
99 return __numeric_formatter(fmt.chars(), value, loc);
104 return __numeric_formatter(fmt.chars(), value, loc);
109 return __floating_point_formatter(fmt.chars(), value, loc);
114 return __floating_point_formatter(fmt.chars(), value, loc);
119 return __floating_point_formatter(fmt.chars(), value, loc);
124 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);
129 return __date_time_formatter(fmt.chars(), value, 0, loc);
132template<
typename type_t,
typename period_t>
134 return __duration_formatter(fmt.chars(), value, loc);
139 return __character_formatter(fmt.chars(), value, loc);
144 return __character_formatter(fmt.chars(), value, loc);
149 return __character_formatter(fmt.chars(), value, loc);
154 return __character_formatter(fmt.chars(), value, loc);
157template<
typename value_t>
159 return to_string(value, fmt, std::locale());
163 return to_string(value, fmt, std::locale());
168 if (value == std::partial_ordering::less)
return "less";
169 if (value == std::partial_ordering::greater)
return "greater";
175 if (value == std::strong_ordering::less)
return "less";
176 if (value == std::strong_ordering::greater)
return "greater";
182 if (value == std::weak_ordering::less)
return "less";
183 if (value == std::weak_ordering::greater)
return "greater";
187template<
typename value_t>
189 if (!value)
return "(null)";
190 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(value), loc);
193template<
typename value_t>
195 if (!value)
return "(null)";
196 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(value), loc);
199template<
typename type_t>
201 if (!value)
return "(null)";
202 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(
value.get()), loc);
205template<
typename type_t>
207 if (!value)
return "(null)";
208 return __numeric_formatter(fmt.chars(),
reinterpret_cast<intptr>(
value.get()), loc);
213 auto iterator = __any_stringer__.find(std::type_index(
value.type()));
217template<
typename type_t>
219 return !
value.has_value() ?
"(null)" : std::string {
"("} +
to_string(
value.value(), fmt, loc).chars() + std::string {
")"};
232template<
typename type1_t,
typename type2_t>
234 return std::string {
"("} +
to_string(
value.first, fmt, loc).chars() + std::string {
", "} +
to_string(
value.second, fmt, loc).chars() + std::string {
")"};
237template<
typename type_t,
unsigned n_t,
unsigned last_t>
238[[nodiscard]]
inline auto 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) ->
xtd::string {
239 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);
242template<
typename type_t,
unsigned n_t>
243[[nodiscard]]
inline auto 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) ->
xtd::string {
244 return str +
xtd::to_string(std::get<n_t>(value), fmt, loc).chars();
247template<
typename ...types_t>
249 return __xtd_tuple_stringer < std::tuple<types_t ...>, 0,
sizeof...(types_t) - 1 >::to_string(std::string {
"("},
value, fmt, loc) +
")";
252template<
typename iterator_t>
253[[nodiscard]]
inline auto __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) -> std::string {
254 if (iterator == end)
return str;
256 return __xtd_iterator_to_string(new_str, ++iterator, begin, end, fmt, loc);
259template<
typename iterator_t>
260[[nodiscard]]
inline auto __xtd_sequence_container_to_string(
const iterator_t& begin,
const iterator_t& end,
const xtd::string& fmt,
const std::locale& loc) -> std::string {
261 return __xtd_iterator_to_string(
"[", begin, begin, end, fmt, loc) +
"]";
264template<xtd::iterable iterable_t>
265[[nodiscard]]
inline auto __xtd_iterable_to_string(
const iterable_t& values,
const xtd::string& fmt,
const std::locale& loc) -> std::string {
266 std::ostringstream oss;
270 auto& mutable_values =
const_cast<iterable_t&
>(values);
271 for (
const auto value : mutable_values) {
272 if (!first) oss <<
", ";
280template<
typename type_t, xtd::usize size>
282 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
285template<xtd::usize size>
288 for (
auto index =
xtd::usize {0}; index < values.length(); ++index)
289 result += (index ?
", " :
"") +
to_string(
static_cast<bool>(values[index]), fmt, loc);
293template<
typename type_t,
typename allocator_t>
295 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
298template<
typename type_t,
typename allocator_t>
300 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
303template<
typename type_t>
305 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
308template<
typename type_t,
typename allocator_t>
310 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
313template<
typename type_t,
typename container_t>
315 struct accessor :
public std::queue<type_t> {
static auto get() {
return &accessor::c;}};
316 const auto& underlying_items = values.*accessor::get();
317 return __xtd_sequence_container_to_string(underlying_items.begin(), underlying_items.end(), fmt, loc);
320template<
typename type_t,
typename container_t>
322 struct std_priority_queue :
public std::queue<type_t> {
323 std_priority_queue(
const std::priority_queue<type_t>& queue) :
ptr {reinterpret_cast<const std_priority_queue*>(&
queue)} {}
324 auto begin()
const {
return ptr->c.begin();}
325 auto end()
const {
return ptr->c.end();}
326 const std_priority_queue*
ptr;
328 auto items = std_priority_queue {values};
329 return __xtd_sequence_container_to_string(items.begin(), items.end(), fmt, loc);
332template<
typename type_t,
typename container_t>
334 struct accessor :
public std::stack<type_t> {
static auto get() {
return &accessor::c;}};
335 const auto& underlying_items = values.*accessor::get();
336 return __xtd_sequence_container_to_string(underlying_items.rbegin(), underlying_items.rend(), fmt, loc);
339template<
typename type_t>
341 return __xtd_sequence_container_to_string(std::begin(values), std::end(values), fmt, loc);
344template<
typename type_t,
typename allocator_t>
346 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
349template<
typename iterator_t>
350[[nodiscard]]
inline auto __xtd_associative_container_to_string(
const iterator_t& begin,
const iterator_t& end,
const xtd::string& fmt,
const std::locale& loc) -> std::string {
351 return __xtd_iterator_to_string(
"{", begin, begin, end, fmt, loc) +
"}";
354template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
356 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
359template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
361 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
364template<
typename key_t,
typename compare_t,
typename allocator_t>
366 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
369template<
typename key_t,
typename compare_t,
typename allocator_t>
371 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
374template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
375[[nodiscard]]
inline auto xtd::to_string(
const std::unordered_map<key_t, value_t, compare_t, allocator_t>& values,
const xtd::string& fmt,
const std::locale& loc) ->
xtd::string {
376 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
379template<
typename key_t,
typename value_t,
typename compare_t,
typename allocator_t>
380[[nodiscard]]
inline auto xtd::to_string(
const std::unordered_multimap<key_t, value_t, compare_t, allocator_t>& values,
const xtd::string& fmt,
const std::locale& loc) ->
xtd::string {
381 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
384template<
typename key_t,
typename compare_t,
typename allocator_t>
386 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
389template<
typename key_t,
typename compare_t,
typename allocator_t>
391 return __xtd_associative_container_to_string(values.begin(), values.end(), fmt, loc);
394template<
typename ...args_t>
396 if (
value.valueless_by_exception())
return "(valueless_by_exception)";
400template<
typename type_t>
401[[nodiscard]]
inline auto xtd::to_string(type_t value,
const std::initializer_list<std::pair<type_t, xtd::string>>& il) ->
xtd::string {
402 std::map<type_t, xtd::string, std::greater<type_t>> values;
403 for (
const auto& item : il) values[item.first] = item.second;
412template<
typename type_t>
414 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
417template<
typename type_t>
419 return __xtd_sequence_container_to_string(values.begin(), values.end(), fmt, loc);
422template<
typename type_t,
typename string_t>
423[[nodiscard]]
inline auto xtd::to_string(type_t value,
const std::map<type_t, string_t, std::greater<type_t>>& values) -> string_t {
424 auto it = values.find(value);
425 if (it != values.end())
return it->second;
427 long long rest =
static_cast<long long>(
value);
428 for (
const auto& item : values) {
429 if (
static_cast<long long>(item.first) != 0 && (rest &
static_cast<long long>(item.first)) ==
static_cast<long long>(item.first)) {
430 if (!result.empty()) result = string_t {
',',
' '} + result;
431 result = item.second + result;
432 rest -=
static_cast<long long>(item.first);
435 if (!result.empty())
return result;
436 return to_string(
static_cast<long long>(value), string_t {
'G'}, std::locale());
439template<
typename type_t,
typename string_t>
440[[nodiscard]]
inline auto xtd::to_string(type_t value,
const std::map<type_t, string_t>& values) -> string_t {
441 std::map<type_t, string_t, std::greater<type_t>> descending_values;
442 for (
const auto& item : values) descending_values[item.first] = item.second;
443 return to_string(value, descending_values);
446template<
typename char_t,
typename value_t>
447[[nodiscard]]
inline auto __string_formatter(
const std::basic_string<char_t>& fmt, value_t value,
const std::locale& loc) -> std::basic_string<char_t> {
448 return __format_stringer<char_t>(value);
452[[nodiscard]]
inline auto __format_stringer<char, bool&>(
bool& value) -> std::string {
457[[nodiscard]]
inline auto __format_stringer<char, xtd::sbyte&>(
xtd::sbyte& value) -> std::string {
462[[nodiscard]]
inline auto __format_stringer<char, const unsigned char&>(
const unsigned char& value) -> std::string {
467[[nodiscard]]
inline auto __format_stringer<char, unsigned char&>(
unsigned char& value) -> std::string {
472[[nodiscard]]
inline auto __format_stringer<char, short&>(
short& value) -> std::string {
477[[nodiscard]]
inline auto __format_stringer<char, unsigned short&>(
unsigned short& value) -> std::string {
482[[nodiscard]]
inline auto __format_stringer<char, int&>(
int& value) -> std::string {
487[[nodiscard]]
inline auto __format_stringer<char, unsigned int&>(
unsigned int& value) -> std::string {
492[[nodiscard]]
inline auto __format_stringer<char, long&>(
long& value) -> std::string {
497[[nodiscard]]
inline auto __format_stringer<char, unsigned long&>(
unsigned long& value) -> std::string {
502[[nodiscard]]
inline auto __format_stringer<char, long long&>(
long long& value) -> std::string {
507[[nodiscard]]
inline auto __format_stringer<char, unsigned long long&>(
unsigned long long& value) -> std::string {
512[[nodiscard]]
inline auto __format_stringer<char, float&>(
float& value) -> std::string {
517[[nodiscard]]
inline auto __format_stringer<char, double&>(
double& value) -> std::string {
522[[nodiscard]]
inline auto __format_stringer<char, long double&>(
long double& value) -> std::string {
527[[nodiscard]]
inline auto __format_stringer<char, std::chrono::system_clock::time_point&>(std::chrono::system_clock::time_point& value) -> std::string {
532[[nodiscard]]
inline auto __format_stringer<char, std::tm&>(tm& value) -> std::string {
537[[nodiscard]]
inline auto __format_stringer<char, xtd::wchar&>(
xtd::wchar& value) -> std::string {
542[[nodiscard]]
inline auto __format_stringer<char, xtd::char8&>(
xtd::char8& value) -> std::string {
547[[nodiscard]]
inline auto __format_stringer<char, xtd::char16&>(
xtd::char16& value) -> std::string {
552[[nodiscard]]
inline auto __format_stringer<char, xtd::char32&>(
xtd::char32& value) -> std::string {
556template<
typename char_t,
typename type_t,
typename period_t = std::ratio<1>>
557auto operator <<(std::basic_ostream<char_t>& os,
const std::chrono::duration<type_t, period_t>& value) -> std::basic_ostream<char_t>& {
558 return os <<
xtd::to_string(value, std::basic_string<char_t> {
'G'}, std::locale());
561template <
class char_t,
typename type_t >
562struct __enum_ostream__<char_t, type_t, std::false_type> {
563 auto to_stream(std::basic_ostream < char_t >& os,
const type_t& value)
noexcept -> std::basic_ostream<char_t>& {
565 return os <<
xtd::to_string(value, std::basic_string < char_t > {}, std::locale {});
Internal vector-like container used as a storage backend for xtd collections.
Definition raw_array.hpp:38
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:40
static auto throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current()) -> void
Throws an exption with specified exception case.
Definition iterable.hpp:15
Definition stream_insertable.hpp:13
Definition textual.hpp:16
generic::queue< xtd::any_object > queue
Represents a first-in, first-out collection of objects.
Definition queue.hpp:27
@ value
Represnets the constant operator precedence (42).
Definition operator_precedence.hpp:30
@ format
The format is not valid.
Definition exception_case.hpp:51
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
std::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
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
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
std::remove_cvref_t< value_t > raw_type
Represents a raw type alias equivalent to std::remove_cvref_t<value_t>.
Definition raw_type.hpp:25
const xtd::collections::generic::helpers::wrap_pointer_iterator< pointer > iterator
Represents the iterator of read_only_span value type.
Definition read_only_span.hpp:75
auto first() const -> read_only_span< type_t, count >
Obtains a subspan consisting of the first count elements of the sequence.
Definition read_only_span.hpp:263
auto begin() const -> const_iterator
Returns an iterator to the beginning.
Definition read_only_span.hpp:200
auto to_string() const noexcept -> xtd::string override
Returns the string representation of this xtd::read_only_span <type_t> object.
Definition read_only_span.hpp:356
auto end() const -> const_iterator
Returns an iterator to the end.
Definition read_only_span.hpp:219
Contains xtd::stream_insertable concept.
Contains xtd::to_string methods.