16 #ifndef COM_BORA_SOFTWARE__BALAU_APPLICATION__FROM_STRING 17 #define COM_BORA_SOFTWARE__BALAU_APPLICATION__FROM_STRING 19 #include <Balau/Type/Impl/FromStringImpl.hpp> 30 inline void fromString(std::string & destination, std::string_view value) {
31 destination = std::string(value.data(), value.length());
40 inline void fromString(std::u16string & destination, std::string_view value) {
41 destination = boost::locale::conv::utf_to_utf<char16_t, char>(std::string(value));
50 inline void fromString(std::u32string & destination, std::string_view value) {
51 destination = boost::locale::conv::utf_to_utf<char32_t, char>(std::string(value));
66 inline void fromString(
char & destination, std::string_view value) {
67 Balau::Impl::validateFromStringValue(value);
70 Balau::Impl::validateCharacter(c);
75 ,
toString(
"Cannot convert code point ", (
long long) c,
" to ascii char.")
79 destination =
static_cast<char>(c);
93 inline void fromString(char32_t & destination, std::string_view value) {
94 Balau::Impl::validateFromStringValue(value);
97 Balau::Impl::validateCharacter(destination);
112 inline void fromString(
signed char & destination, std::string_view value) {
113 long n = Balau::Impl::stringToLong(value);
114 destination = Balau::Impl::safeNumericCast<signed char>(n);
130 inline void fromString(
signed char & destination, std::string_view value,
int base) {
131 long n = Balau::Impl::stringToLong(value, base);
132 destination = Balau::Impl::safeNumericCast<signed char>(n);
147 inline void fromString(
short & destination, std::string_view value) {
148 long n = Balau::Impl::stringToLong(value);
149 destination = Balau::Impl::safeNumericCast<short>(n);
165 inline void fromString(
short & destination, std::string_view value,
int base) {
166 long n = Balau::Impl::stringToLong(value, base);
167 destination = Balau::Impl::safeNumericCast<short>(n);
182 inline void fromString(
int & destination, std::string_view value) {
183 long n = Balau::Impl::stringToLong(value);
184 destination = Balau::Impl::safeNumericCast<int>(n);
200 inline void fromString(
int & destination, std::string_view value,
int base) {
201 long n = Balau::Impl::stringToLong(value, base);
202 destination = Balau::Impl::safeNumericCast<int>(n);
217 inline void fromString(
long & destination, std::string_view value) {
218 destination = Balau::Impl::stringToLong(value);
234 inline void fromString(
long & destination, std::string_view value,
int base) {
235 destination = Balau::Impl::stringToLong(value, base);
250 inline void fromString(
long long & destination, std::string_view value) {
251 destination = Balau::Impl::stringToLongLong(value);
267 inline void fromString(
long long & destination, std::string_view value,
int base) {
268 destination = Balau::Impl::stringToLongLong(value, base);
283 inline void fromString(
unsigned char & destination, std::string_view value) {
284 unsigned long n = Balau::Impl::stringToUnsignedLong(value);
285 destination = Balau::Impl::safeNumericCast<unsigned char>(n);
301 inline void fromString(
unsigned char & destination, std::string_view value,
int base) {
302 unsigned long n = Balau::Impl::stringToUnsignedLong(value, base);
303 destination = Balau::Impl::safeNumericCast<unsigned char>(n);
318 inline void fromString(
unsigned short & destination, std::string_view value) {
319 unsigned long n = Balau::Impl::stringToUnsignedLong(value);
320 destination = Balau::Impl::safeNumericCast<unsigned short>(n);
336 inline void fromString(
unsigned short & destination, std::string_view value,
int base) {
337 unsigned long n = Balau::Impl::stringToUnsignedLong(value, base);
338 destination = Balau::Impl::safeNumericCast<unsigned short>(n);
353 inline void fromString(
unsigned int & destination, std::string_view value) {
354 unsigned long n = Balau::Impl::stringToUnsignedLong(value);
355 destination = Balau::Impl::safeNumericCast<unsigned int>(n);
371 inline void fromString(
unsigned int & destination, std::string_view value,
int base) {
372 unsigned long n = Balau::Impl::stringToUnsignedLong(value, base);
373 destination = Balau::Impl::safeNumericCast<unsigned int>(n);
388 inline void fromString(
unsigned long & destination, std::string_view value) {
389 destination = Balau::Impl::stringToUnsignedLong(value);
405 inline void fromString(
unsigned long & destination, std::string_view value,
int base) {
406 destination = Balau::Impl::stringToUnsignedLong(value, base);
421 inline void fromString(
unsigned long long & destination, std::string_view value) {
422 destination = Balau::Impl::stringToUnsignedLongLong(value);
438 inline void fromString(
unsigned long long & destination, std::string_view value,
int base) {
439 destination = Balau::Impl::stringToUnsignedLongLong(value, base);
454 inline void fromString(
float & destination, std::string_view value) {
455 destination = Balau::Impl::stringToFloat(value);
470 inline void fromString(
double & destination, std::string_view value) {
471 destination = Balau::Impl::stringToDouble(value);
486 inline void fromString(
long double & destination, std::string_view value) {
487 destination = Balau::Impl::stringToLongDouble(value);
500 inline void fromString(
bool & destination, std::string_view value) {
503 if (lower ==
"true") {
505 }
else if (lower ==
"false") {
510 ,
toString(
"Cannot convert \"", value,
"\" to boolean.")
523 inline void fromString16(std::string & destination, std::u16string_view value) {
524 destination = boost::locale::conv::utf_to_utf<char, char16_t>(std::u16string(value));
533 inline void fromString16(std::u16string & destination, std::u16string_view value) {
534 destination = std::u16string(value.data(), value.length());
543 inline void fromString16(std::u32string & destination, std::u16string_view value) {
544 destination = boost::locale::conv::utf_to_utf<char32_t, char16_t>(std::u16string(value));
558 inline void fromString16(
char & destination, std::u16string_view value) {
559 std::string valueStr =
toString(value);
573 inline void fromString16(char32_t & destination, std::u16string_view value) {
574 std::string valueStr =
toString(value);
590 inline void fromString16(
signed char & destination, std::u16string_view value) {
591 std::string valueStr =
toString(value);
592 long n = Balau::Impl::stringToLong(valueStr);
593 destination = Balau::Impl::safeNumericCast<signed char>(n);
608 inline void fromString16(
short & destination, std::u16string_view value) {
609 std::string valueStr =
toString(value);
625 inline void fromString16(
int & destination, std::u16string_view value) {
626 std::string valueStr =
toString(value);
642 inline void fromString16(
long & destination, std::u16string_view value) {
643 std::string valueStr =
toString(value);
659 inline void fromString16(
long long & destination, std::u16string_view value) {
660 std::string valueStr =
toString(value);
676 inline void fromString16(
unsigned char & destination, std::u16string_view value) {
677 std::string valueStr =
toString(value);
693 inline void fromString16(
unsigned short & destination, std::u16string_view value) {
694 std::string valueStr =
toString(value);
710 inline void fromString16(
unsigned int & destination, std::u16string_view value) {
711 std::string valueStr =
toString(value);
727 inline void fromString16(
unsigned long & destination, std::u16string_view value) {
728 std::string valueStr =
toString(value);
744 inline void fromString16(
unsigned long long & destination, std::u16string_view value) {
745 std::string valueStr =
toString(value);
761 inline void fromString16(
float & destination, std::u16string_view value) {
762 std::string valueStr =
toString(value);
778 inline void fromString16(
double & destination, std::u16string_view value) {
779 std::string valueStr =
toString(value);
795 inline void fromString16(
long double & destination, std::u16string_view value) {
796 std::string valueStr =
toString(value);
810 inline void fromString16(
bool & destination, std::u16string_view value) {
811 std::string valueStr =
toString(value);
823 inline void fromString32(std::string & destination, std::u32string_view value) {
824 destination = boost::locale::conv::utf_to_utf<char, char32_t>(std::u32string(value));
833 inline void fromString32(std::u16string & destination, std::u32string_view value) {
834 destination = boost::locale::conv::utf_to_utf<char16_t, char32_t>(std::u32string(value));
843 inline void fromString32(std::u32string & destination, std::u32string_view value) {
844 destination = std::u32string(value.data(), value.length());
858 inline void fromString32(
char & destination, std::u32string_view value) {
859 std::string valueStr =
toString(value);
873 inline void fromString32(char32_t & destination, std::u32string_view value) {
874 Balau::Impl::validateFromString32Value(value);
875 destination = value[0];
890 inline void fromString32(
signed char & destination, std::u32string_view value) {
891 std::string valueStr =
toString(value);
907 inline void fromString32(
short & destination, std::u32string_view value) {
908 std::string valueStr =
toString(value);
924 inline void fromString32(
int & destination, std::u32string_view value) {
925 std::string valueStr =
toString(value);
941 inline void fromString32(
long & destination, std::u32string_view value) {
942 std::string valueStr =
toString(value);
958 inline void fromString32(
long long & destination, std::u32string_view value) {
959 std::string valueStr =
toString(value);
975 inline void fromString32(
unsigned char & destination, std::u32string_view value) {
976 std::string valueStr =
toString(value);
992 inline void fromString32(
unsigned short & destination, std::u32string_view value) {
993 std::string valueStr =
toString(value);
1009 inline void fromString32(
unsigned int & destination, std::u32string_view value) {
1010 std::string valueStr =
toString(value);
1026 inline void fromString32(
unsigned long & destination, std::u32string_view value) {
1027 std::string valueStr =
toString(value);
1043 inline void fromString32(
unsigned long long & destination, std::u32string_view value) {
1044 std::string valueStr =
toString(value);
1061 std::string valueStr =
toString(value);
1077 inline void fromString32(
double & destination, std::u32string_view value) {
1078 std::string valueStr =
toString(value);
1094 inline void fromString32(
long double & destination, std::u32string_view value) {
1095 std::string valueStr =
toString(value);
1110 std::string valueStr =
toString(value);
1132 template <
typename T>
void operator () (T & destination, std::string_view value)
const {
1148 template <
typename T>
void operator () (T & destination, std::u16string_view value)
const {
1164 template <
typename T>
void operator () (T & destination, std::u32string_view value)
const {
1169 #endif // COM_BORA_SOFTWARE__BALAU_APPLICATION__FROM_STRING void fromString(std::string &destination, std::string_view value)
Sets the destination value to the supplied value.
Definition: FromString.hpp:30
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
Balau::U8String< AllocatorT > toString(const BalauException &e)
Base class toString<AllocatorT> function for Balau exceptions.
Definition: BalauException.hpp:122
static char32_t getNextUtf8Safe(const std::string_view &text, int &offset)
Get the next code point from the UTF-8 string view (validating version).
Definition: Character.hpp:198
Thrown when a conversion fails.
Definition: BalauException.hpp:170
static std::string toLower(const std::string_view &s)
Convert the supplied UTF-8 string to lowercase.
Definition: Strings.hpp:457
Template class based from-string function for use in template classes.
Definition: FromString.hpp:1119
void fromString16(std::string &destination, std::u16string_view value)
Sets the destination value to a UTF-8 version of the supplied UTF-16 string.
Definition: FromString.hpp:523
void fromString32(std::string &destination, std::u32string_view value)
Sets the destination value to a UTF-8 version of the supplied UTF-32 string.
Definition: FromString.hpp:823