16 #ifndef COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_A 17 #define COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_A 20 #include <Balau/Type/Impl/ToStringImpl.hpp> 21 #include <Balau/ThirdParty/Boost/Locale/EncodingUtf.hpp> 23 #include <boost/lexical_cast.hpp> 24 #include <boost/locale.hpp> 25 #include <boost/utility/string_view.hpp> 27 #include <forward_list> 30 #include <unordered_set> 31 #include <unordered_map> 40 template <
typename AllocatorT>
41 using U8String = std::basic_string<char, std::char_traits<char>, AllocatorT>;
46 template <
typename AllocatorT>
47 using U16String = std::basic_string<char16_t, std::char_traits<char16_t>, AllocatorT>;
52 template <
typename AllocatorT>
53 using U32String = std::basic_string<char32_t, std::char_traits<char32_t>, AllocatorT>;
58 template <
typename AllocatorT>
59 using U8OStringStream = std::basic_ostringstream<char, std::char_traits<char>, AllocatorT>;
64 template <
typename AllocatorT>
65 using U16OStringStream = std::basic_ostringstream<char16_t, std::char_traits<char16_t>, AllocatorT>;
70 template <
typename AllocatorT>
71 using U32OStringStream = std::basic_ostringstream<char32_t, std::char_traits<char32_t>, AllocatorT>;
75 template <
typename AllocatorT,
typename P1,
typename P2,
typename ... P>
78 template <
typename AllocatorT,
typename P1,
typename P2,
typename ... P>
81 template <
typename AllocatorT,
typename P1,
typename P2,
typename ... P>
89 template <
typename AllocatorT>
97 template <
typename AllocatorT>
105 template <
typename AllocatorT>
110 #ifndef BALAU_USE_BOOST_STRING_VIEW 115 template <
typename AllocatorT>
125 template <
typename AllocatorT>
127 return Balau::Boost::Locale::Conv::utf_to_utf<char, char16_t, AllocatorT>(value);
133 template <
typename AllocatorT>
135 return Balau::Boost::Locale::Conv::utf_to_utf<char, char16_t, AllocatorT>(std::u16string(value));
141 template <
typename AllocatorT>
143 return Balau::Boost::Locale::Conv::utf_to_utf<char, char32_t, AllocatorT>(value);
149 template <
typename AllocatorT>
151 return Balau::Boost::Locale::Conv::utf_to_utf<char, char32_t, AllocatorT>(std::u32string(value));
157 template <
typename AllocatorT>
167 template <
typename AllocatorT>
171 return toString<AllocatorT>(str);
177 template <
typename AllocatorT>
181 return toString<AllocatorT>(str);
187 template <
typename AllocatorT>
189 return Balau::Impl::toString<AllocatorT>(
"%d", (int) value);
195 template <
typename AllocatorT>
197 return Balau::Impl::toString<AllocatorT>(
"%d", (int) value);
203 template <
typename AllocatorT>
205 return Balau::Impl::toString<AllocatorT>(
"%d", (int) value);
211 template <
typename AllocatorT>
213 return Balau::Impl::toString<AllocatorT>(
"%ld", value);
219 template <
typename AllocatorT>
221 return Balau::Impl::toString<AllocatorT>(
"%lld", value);
227 template <
typename AllocatorT>
229 return Balau::Impl::toString<AllocatorT>(
"%u", (
unsigned int) value);
235 template <
typename AllocatorT>
237 return Balau::Impl::toString<AllocatorT>(
"%u", (
unsigned int) value);
243 template <
typename AllocatorT>
245 return Balau::Impl::toString<AllocatorT>(
"%u", value);
251 template <
typename AllocatorT>
253 return Balau::Impl::toString<AllocatorT>(
"%lu", value);
259 template <
typename AllocatorT>
261 return Balau::Impl::toString<AllocatorT>(
"%llu", value);
267 template <
typename AllocatorT>
275 template <
typename AllocatorT>
283 template <
typename AllocatorT>
291 template <
typename T,
typename AllocatorT>
293 return toString<AllocatorT>(value.real(),
" + j", value.imag());
299 template <
typename AllocatorT>
301 return value ?
"true" :
"false";
307 template <
typename AllocatorT>
312 template <
typename AllocatorT>
313 std::u16string
toString16(
const char16_t * value);
315 template <
typename AllocatorT>
316 std::u32string
toString32(
const char32_t * value);
321 template <
typename AllocatorT>
323 return toString<AllocatorT>(toString16<AllocatorT>(value));
329 template <
typename AllocatorT>
331 return toString<AllocatorT>(toString32<AllocatorT>(value));
340 template <
typename AllocatorT>
342 return toString<AllocatorT>((size_t) ptr);
351 template <
typename AllocatorT>
359 template <
typename AllocatorT>
367 template <
typename AllocatorT>
375 template <
typename AllocatorT,
typename F,
typename S>
385 template <
typename AllocatorT,
typename ... T,
template <
typename ...>
class C>
391 for (
const auto & e : c) {
392 builder += prefix + toString<AllocatorT>(e);
409 #define BALAU_CONTAINER1_TO_STRING_A(CONTAINER_TYPE) \ 410 template <typename T, typename AllocatorT> \ 411 inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T> & c) { \ 412 return toStringHelper<AllocatorT>(c); \ 418 #define BALAU_CONTAINER2_TO_STRING_A(CONTAINER_TYPE) \ 419 template <typename AllocatorT, typename T, typename U> \ 420 inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U> & c) { \ 421 return toStringHelper<AllocatorT>(c); \ 427 #define BALAU_CONTAINER3_TO_STRING_A(CONTAINER_TYPE) \ 428 template <typename AllocatorT, typename T, typename U, typename V> \ 429 inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U, V> & c) { \ 430 return toStringHelper<AllocatorT>(c); \ 436 #define BALAU_CONTAINER4_TO_STRING_A(CONTAINER_TYPE) \ 437 template <typename AllocatorT, typename T, typename U, typename V, typename W> \ 438 inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U, V, W> & c) { \ 439 return toStringHelper<AllocatorT>(c); \ 445 #define BALAU_CONTAINER5_TO_STRING_A(CONTAINER_TYPE) \ 446 template <typename AllocatorT, typename T, typename U, typename V, typename W, typename X> \ 447 inline Balau::U8String<AllocatorT> toString(const CONTAINER_TYPE<T, U, V, W, X> & c) { \ 448 return toStringHelper<AllocatorT>(c); \ 467 template <
typename AllocatorT,
typename T,
size_t N>
474 return toStringHelper<AllocatorT>(c);
483 template <
typename AllocatorT,
typename P1,
typename P2,
typename ... P>
493 template <
typename AllocatorT>
495 return Balau::Boost::Locale::Conv::utf_to_utf<char16_t, char, AllocatorT>(value);
501 template <
typename AllocatorT>
509 template <
typename AllocatorT>
515 #ifndef BALAU_USE_BOOST_STRING_VIEW 520 template <
typename AllocatorT>
530 template <
typename AllocatorT>
538 template <
typename AllocatorT>
546 template <
typename AllocatorT>
554 template <
typename AllocatorT>
556 return Balau::Boost::Locale::Conv::utf_to_utf<char16_t, char32_t, AllocatorT>(value);
562 template <
typename AllocatorT>
566 return toString16<AllocatorT>(str);
572 template <
typename AllocatorT>
582 template <
typename AllocatorT>
586 return toString16<AllocatorT>(str);
592 template <
typename AllocatorT>
594 return toString16<AllocatorT>(toString<AllocatorT>(value));
600 template <
typename AllocatorT>
602 return toString16<AllocatorT>(toString<AllocatorT>(value));
608 template <
typename AllocatorT>
610 return toString16<AllocatorT>(toString<AllocatorT>(value));
616 template <
typename AllocatorT>
618 return toString16<AllocatorT>(toString<AllocatorT>(value));
624 template <
typename AllocatorT>
626 return toString16<AllocatorT>(toString<AllocatorT>(value));
632 template <
typename AllocatorT>
634 return toString16<AllocatorT>(toString<AllocatorT>(value));
640 template <
typename AllocatorT>
642 return toString16<AllocatorT>(toString<AllocatorT>(value));
648 template <
typename AllocatorT>
650 return toString16<AllocatorT>(toString<AllocatorT>(value));
656 template <
typename AllocatorT>
658 return toString16<AllocatorT>(toString<AllocatorT>(value));
664 template <
typename AllocatorT>
666 return toString16<AllocatorT>(toString<AllocatorT>(value));
672 template <
typename AllocatorT>
674 return toString16<AllocatorT>(toString<AllocatorT>(value));
680 template <
typename AllocatorT>
682 return toString16<AllocatorT>(toString<AllocatorT>(value));
688 template <
typename AllocatorT>
690 return toString16<AllocatorT>(toString<AllocatorT>(value));
696 template <
typename T,
typename AllocatorT>
698 return toString16<AllocatorT>(value.real(),
" + j", value.imag());
704 template <
typename AllocatorT>
706 return value ? u
"true" : u
"false";
712 template <
typename AllocatorT>
714 return toString16<AllocatorT>(toString<AllocatorT>((value)));
720 template <
typename AllocatorT>
722 return std::u16string(value);
728 template <
typename AllocatorT>
730 return toString16<AllocatorT>(toString32<AllocatorT>(value));
739 template <
typename AllocatorT>
741 return toString16<AllocatorT>((size_t) ptr);
750 template <
typename AllocatorT>
758 template <
typename AllocatorT>
760 return toString16<AllocatorT>(value.name());
766 template <
typename AllocatorT>
774 template <
typename AllocatorT,
typename F,
typename S>
776 return std::u16string(u
"{ ") + toString16<AllocatorT>(p.first) + u
", " + toString16<AllocatorT>(p.second) + u
" }";
784 template <
typename AllocatorT,
typename ... T,
template <
typename ...>
class C>
786 std::u16string builder = u
"{";
787 std::u16string prefix = u
" ";
790 for (
const auto & e : c) {
791 builder += prefix + toString16<AllocatorT>(e);
808 #define BALAU_CONTAINER1_TO_STRING16_A(CONTAINER_TYPE) \ 809 template <typename AllocatorT, typename T> \ 810 inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T> & c) { \ 811 return toString16Helper<AllocatorT>(c); \ 817 #define BALAU_CONTAINER2_TO_STRING16_A(CONTAINER_TYPE) \ 818 template <typename AllocatorT, typename T, typename U> \ 819 inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U> & c) { \ 820 return toString16Helper<AllocatorT>(c); \ 826 #define BALAU_CONTAINER3_TO_STRING16_A(CONTAINER_TYPE) \ 827 template <typename AllocatorT, typename T, typename U, typename V> \ 828 inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U, V> & c) { \ 829 return toString16Helper<AllocatorT>(c); \ 835 #define BALAU_CONTAINER4_TO_STRING16_A(CONTAINER_TYPE) \ 836 template <typename AllocatorT, typename T, typename U, typename V, typename W> \ 837 inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U, V, W> & c) { \ 838 return toString16Helper<AllocatorT>(c); \ 844 #define BALAU_CONTAINER5_TO_STRING16_A(CONTAINER_TYPE) \ 845 template <typename AllocatorT, typename T, typename U, typename V, typename W, typename X> \ 846 inline Balau::U16String<AllocatorT> toString16(const CONTAINER_TYPE<T, U, V, W, X> & c) { \ 847 return toString16Helper<AllocatorT>(c); \ 866 template <
typename AllocatorT,
typename P1,
typename P2,
typename ... P>
874 return toString16<AllocatorT>(p1)
875 + toString16<AllocatorT>(p2)
884 template <
typename AllocatorT>
892 template <
typename AllocatorT>
894 return Balau::Boost::Locale::Conv::utf_to_utf<char32_t, char, AllocatorT>(value);
900 template <
typename AllocatorT>
905 #ifndef BALAU_USE_BOOST_STRING_VIEW 910 template <
typename AllocatorT>
920 template <
typename AllocatorT>
922 return Balau::Boost::Locale::Conv::utf_to_utf<char32_t, char16_t, AllocatorT>(value);
928 template <
typename AllocatorT>
936 template <
typename AllocatorT>
944 template <
typename AllocatorT>
952 template <
typename AllocatorT>
956 return toString32<AllocatorT>(str);
962 template <
typename AllocatorT>
966 return toString32<AllocatorT>(str);
972 template <
typename AllocatorT>
982 template <
typename AllocatorT>
984 return toString32<AllocatorT>(toString<AllocatorT>(value));
990 template <
typename AllocatorT>
992 return toString32<AllocatorT>(toString<AllocatorT>(value));
998 template <
typename AllocatorT>
1000 return toString32<AllocatorT>(toString<AllocatorT>(value));
1006 template <
typename AllocatorT>
1008 return toString32<AllocatorT>(toString<AllocatorT>(value));
1014 template <
typename AllocatorT>
1016 return toString32<AllocatorT>(toString<AllocatorT>(value));
1022 template <
typename AllocatorT>
1024 return toString32<AllocatorT>(toString<AllocatorT>(value));
1030 template <
typename AllocatorT>
1032 return toString32<AllocatorT>(toString<AllocatorT>(value));
1038 template <
typename AllocatorT>
1040 return toString32<AllocatorT>(toString<AllocatorT>(value));
1046 template <
typename AllocatorT>
1048 return toString32<AllocatorT>(toString<AllocatorT>(value));
1054 template <
typename AllocatorT>
1056 return toString32<AllocatorT>(toString<AllocatorT>(value));
1062 template <
typename AllocatorT>
1064 return toString32<AllocatorT>(toString<AllocatorT>(value));
1070 template <
typename AllocatorT>
1072 return toString32<AllocatorT>(toString<AllocatorT>(value));
1078 template <
typename AllocatorT>
1080 return toString32<AllocatorT>(toString<AllocatorT>(value));
1086 template <
typename T,
typename AllocatorT>
1088 return toString32<AllocatorT>(value.real(),
" + j", value.imag());
1094 template <
typename AllocatorT>
1096 return value ? U
"true" : U
"false";
1102 template <
typename AllocatorT>
1104 return toString32<AllocatorT>(toString<AllocatorT>((value)));
1110 template <
typename AllocatorT>
1112 return toString32<AllocatorT>(toString16<AllocatorT>((value)));
1118 template <
typename AllocatorT>
1129 template <
typename AllocatorT>
1131 return toString32<AllocatorT>((size_t) ptr);
1140 template <
typename AllocatorT>
1148 template <
typename AllocatorT>
1150 return toString32<AllocatorT>(value.name());
1156 template <
typename AllocatorT>
1164 template <
typename AllocatorT,
typename F,
typename S>
1167 + toString32<AllocatorT>(p.first)
1169 + toString32<AllocatorT>(p.second)
1178 template <
typename AllocatorT,
typename ... T,
template <
typename ...>
class C>
1184 for (
const auto & e : c) {
1185 builder += prefix + toString32<AllocatorT>(e);
1202 #define BALAU_CONTAINER1_TO_STRING32_A(CONTAINER_TYPE) \ 1203 template <typename AllocatorT, typename T> \ 1204 inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T> & c) { \ 1205 return toString32Helper<AllocatorT>(c); \ 1211 #define BALAU_CONTAINER2_TO_STRING32_A(CONTAINER_TYPE) \ 1212 template <typename AllocatorT, typename T, typename U> \ 1213 inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U> & c) { \ 1214 return toString32Helper<AllocatorT>(c); \ 1220 #define BALAU_CONTAINER3_TO_STRING32_A(CONTAINER_TYPE) \ 1221 template <typename AllocatorT, typename T, typename U, typename V> \ 1222 inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U, V> & c) { \ 1223 return toString32Helper<AllocatorT>(c); \ 1229 #define BALAU_CONTAINER4_TO_STRING32_A(CONTAINER_TYPE) \ 1230 template <typename AllocatorT, typename T, typename U, typename V, typename W> \ 1231 inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U, V, W> & c) { \ 1232 return toString32Helper<AllocatorT>(c); \ 1238 #define BALAU_CONTAINER5_TO_STRING32_A(CONTAINER_TYPE) \ 1239 template <typename AllocatorT, typename T, typename U, typename V, typename W, typename X> \ 1240 inline Balau::U32String<AllocatorT> toString32(const CONTAINER_TYPE<T, U, V, W, X> & c) { \ 1241 return toString32Helper<AllocatorT>(c); \ 1260 template <
typename AllocatorT,
typename P1,
typename P2,
typename ... P>
1268 return toString32<AllocatorT>(p1)
1269 + toString32<AllocatorT>(p2)
1278 template <
typename CharT,
typename AllocatorT = std::allocator<CharT>>
struct ToString;
1285 template <
typename AllocatorT>
struct ToString<char, AllocatorT> {
1287 return toString<AllocatorT>(object);
1296 template <
typename AllocatorT>
struct ToString<char16_t, AllocatorT> {
1298 return toString16<AllocatorT>(object);
1307 template <
typename AllocatorT>
struct ToString<char32_t, AllocatorT> {
1309 return toString32<AllocatorT>(object);
1313 #endif // COM_BORA_SOFTWARE__BALAU_APPLICATION__TO_STRING_A std::basic_ostringstream< char16_t, std::char_traits< char16_t >, AllocatorT > U16OStringStream
UTF-16 output string stream type with selectable allocator.
Definition: ToStringA.hpp:65
#define BALAU_CONTAINER3_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has three template parameters.
Definition: ToStringA.hpp:826
Balau::U8String< AllocatorT > toStringHelper(const C< T ... > &c)
Helper for container to UTF-8 string functions.
Definition: ToStringA.hpp:386
std::u16string toString16Helper(const C< T ... > &c)
Helper for container to UTF-16 string functions.
Definition: ToStringA.hpp:785
std::basic_string< char16_t, std::char_traits< char16_t >, AllocatorT > U16String
UTF-16 string type with selectable allocator.
Definition: ToStringA.hpp:47
#define BALAU_CONTAINER5_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has five template parameters.
Definition: ToStringA.hpp:844
#define BALAU_CONTAINER3_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has three template parameters.
Definition: ToStringA.hpp:427
std::basic_ostringstream< char32_t, std::char_traits< char32_t >, AllocatorT > U32OStringStream
UTF-32 output string stream type with selectable allocator.
Definition: ToStringA.hpp:71
#define BALAU_CONTAINER4_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has four template parameters.
Definition: ToStringA.hpp:1229
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
Balau::U16String< AllocatorT > toString16(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringA.hpp:873
#define BALAU_CONTAINER5_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has five template parameters.
Definition: ToStringA.hpp:445
Core includes, typedefs and functions.
std::basic_ostringstream< char, std::char_traits< char >, AllocatorT > U8OStringStream
UTF-8 output string stream type with selectable allocator.
Definition: ToStringA.hpp:59
std::basic_string< char32_t, std::char_traits< char32_t >, AllocatorT > U32String
UTF-32 string type with selectable allocator.
Definition: ToStringA.hpp:53
#define BALAU_CONTAINER4_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has four template parameters.
Definition: ToStringA.hpp:835
#define BALAU_CONTAINER5_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has five template parameters.
Definition: ToStringA.hpp:1238
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
Balau::U32String< AllocatorT > toString32Helper(const C< T ... > &c)
Helper for container to UTF-8 string functions.
Definition: ToStringA.hpp:1179
#define BALAU_CONTAINER2_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has two template parameters.
Definition: ToStringA.hpp:1211
#define BALAU_CONTAINER3_TO_STRING32_A(CONTAINER_TYPE)
Define a UTF-32 to-string function for a container that has three template parameters.
Definition: ToStringA.hpp:1220
#define BALAU_CONTAINER2_TO_STRING16_A(CONTAINER_TYPE)
Define a UTF-16 to-string function for a container that has two template parameters.
Definition: ToStringA.hpp:817
Balau::U32String< AllocatorT > toString32(const P1 &p1, const P2 &p2, const P &... p)
Concatenates the to-string values of the input arguments.
Definition: ToStringA.hpp:1267
#define BALAU_CONTAINER2_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has two template parameters.
Definition: ToStringA.hpp:418
Template class based to-string function for use in template classes.
Definition: ToStringA.hpp:1278
Balau::U8String< AllocatorT > toString(LoggingLevel level)
Print the logging level as a UTF-8 string.
Definition: LoggingLevel.hpp:73
#define BALAU_CONTAINER4_TO_STRING_A(CONTAINER_TYPE)
Define a UTF-8 to-string function for a container that has four template parameters.
Definition: ToStringA.hpp:436