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 = {
"0001020304050607080910111213141516171819" 29 "2021222324252627282930313233343536373839" 30 "4041424344454647484950515253545556575859" 31 "6061626364656667686970717273747576777879" 32 "8081828384858687888990919293949596979899"};
34 auto bufferEnd = buffer.end();
39 const unsigned int index =
static_cast<unsigned int>((value % 100) * 2);
41 *--bufferEnd = DIGITS[index + 1];
42 *--bufferEnd = DIGITS[index];
47 *--bufferEnd =
static_cast<char>(
'0' + value);
51 const unsigned int index =
static_cast<unsigned int>(value * 2);
52 *--bufferEnd = DIGITS[index + 1];
53 *--bufferEnd = DIGITS[index];
75 typename std::enable_if<std::is_unsigned<T>::value,
int>::type = 0>
91 template <typename T, typename std::enable_if<std::is_signed<T>::value,
int>::type = 0>
94 using unsigned_type =
typename std::make_unsigned<T>::type;
95 unsigned_type absValue =
static_cast<unsigned_type
>(value);
96 const bool isNegative = value < 0;
98 absValue = 0 - absValue;
115 std::array<char, 24>& floatingPartBuffer,
float value,
const char*& integerPartString,
116 const char*& floatingPartString)
118 if (value >= static_cast<float>(std::numeric_limits<int64_t>::max()))
120 integerPartString =
"+Inf";
121 floatingPartString =
nullptr;
123 else if (value <= static_cast<float>(std::numeric_limits<int64_t>::min()))
125 integerPartString =
"-Inf";
126 floatingPartString =
nullptr;
130 const int64_t integerPart =
static_cast<int64_t
>(value);
131 const int64_t floatingPart =
static_cast<int64_t
>(
132 (value -
static_cast<float>(integerPart)) * 1e3F);
133 const int64_t floatingPartAbs = (floatingPart < 0) ? 0 - floatingPart : floatingPart;
148 return value ?
"true" :
"false";
159 template <
typename ALLOC,
typename T>
162 std::array<char, 24> buffer = {};
175 template <
typename ALLOC>
188 template <
typename T>
191 return toString<std::allocator<char>>(value);
196 #endif // ifndef ZSERIO_STRING_CONVERT_UTIL_H_INC 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())
const char * convertIntToString(std::array< char, 24 > &buffer, T value)
const char * convertBoolToString(bool value)
std::basic_string< char, std::char_traits< char >, RebindAlloc< ALLOC, char >> string