1 #ifndef ZSERIO_STRING_CONVERT_UTIL_H_INC
2 #define ZSERIO_STRING_CONVERT_UTIL_H_INC
25 typename std::enable_if<std::is_unsigned<T>::value && !std::is_same<T, bool>::value,
int>::type = 0>
28 static const std::array<char, 201> DIGITS = {
29 "0001020304050607080910111213141516171819"
30 "2021222324252627282930313233343536373839"
31 "4041424344454647484950515253545556575859"
32 "6061626364656667686970717273747576777879"
33 "8081828384858687888990919293949596979899"};
35 auto bufferEnd = buffer.end();
40 const unsigned int index =
static_cast<unsigned int>((value % 100) * 2);
42 *(--bufferEnd) = DIGITS[index + 1];
43 *(--bufferEnd) = DIGITS[index];
48 *(--bufferEnd) =
static_cast<char>(
'0' + value);
52 const unsigned int index =
static_cast<unsigned int>(value * 2);
53 *(--bufferEnd) = DIGITS[index + 1];
54 *(--bufferEnd) = DIGITS[index];
77 template <typename T, typename std::enable_if<std::is_unsigned<T>::value,
int>::type = 0>
93 template <typename T, typename std::enable_if<std::is_signed<T>::value,
int>::type = 0>
96 using unsigned_type =
typename std::make_unsigned<T>::type;
97 unsigned_type absValue =
static_cast<unsigned_type
>(value);
98 const bool isNegative = value < 0;
101 absValue =
static_cast<unsigned_type
>(0 - absValue);
119 std::array<char, 24>& floatingPartBuffer,
float value,
const char*& integerPartString,
120 const char*& floatingPartString)
122 if (value >=
static_cast<float>(std::numeric_limits<int64_t>::max()))
124 integerPartString =
"+Inf";
125 floatingPartString =
nullptr;
127 else if (value <=
static_cast<float>(std::numeric_limits<int64_t>::min()))
129 integerPartString =
"-Inf";
130 floatingPartString =
nullptr;
134 const int64_t integerPart =
static_cast<int64_t
>(value);
135 const int64_t floatingPart =
136 static_cast<int64_t
>((value -
static_cast<float>(integerPart)) * 1e3F);
137 const int64_t floatingPartAbs = (floatingPart < 0) ? 0 - floatingPart : floatingPart;
152 return value ?
"true" :
"false";
163 template <
typename ALLOC,
typename T>
166 std::array<char, 24> buffer = {};
179 template <
typename ALLOC>
192 template <
typename T>
195 return toString<std::allocator<char>>(value);
const char * convertIntToString(std::array< char, 24 > &buffer, T value)
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char > > string
const char * convertBoolToString(bool value)
void convertFloatToString(std::array< char, 24 > &integerPartBuffer, std::array< char, 24 > &floatingPartBuffer, float value, const char *&integerPartString, const char *&floatingPartString)
string< ALLOC > toString(T value, const ALLOC &allocator=ALLOC())