1231 C4_STATIC_ASSERT(std::is_signed<T>::value);
1232 C4_ASSERT(radix == 2 || radix == 8 || radix == 10 || radix == 16);
1233 C4_SUPPRESS_WARNING_GCC_PUSH
1234 #if (defined(__GNUC__) && (__GNUC__ >= 7))
1235 C4_SUPPRESS_WARNING_GCC(
"-Wstringop-overflow")
1239 if C4_LIKELY(v != std::numeric_limits<T>::min())
1245 if C4_LIKELY(buf.len > 0)
1249 unsigned total_digits = 0;
1254 total_digits = pos + (unsigned)(num_digits > total_digits ? num_digits : total_digits);
1255 if C4_LIKELY(buf.len >= total_digits)
1260 total_digits = pos + 2u + (
unsigned)(num_digits > total_digits ? num_digits : total_digits);
1261 if C4_LIKELY(buf.len >= total_digits)
1263 buf.str[pos + 0] =
'0';
1264 buf.str[pos + 1] =
'x';
1265 write_hex(buf.sub(pos + 2), v, num_digits);
1270 total_digits = pos + 2u + (unsigned)(num_digits > total_digits ? num_digits : total_digits);
1271 if C4_LIKELY(buf.len >= total_digits)
1273 buf.str[pos + 0] =
'0';
1274 buf.str[pos + 1] =
'b';
1275 write_bin(buf.sub(pos + 2), v, num_digits);
1280 total_digits = pos + 2u + (unsigned)(num_digits > total_digits ? num_digits : total_digits);
1281 if C4_LIKELY(buf.len >= total_digits)
1283 buf.str[pos + 0] =
'0';
1284 buf.str[pos + 1] =
'o';
1285 write_oct(buf.sub(pos + 2), v, num_digits);
1289 return total_digits;
1291 C4_SUPPRESS_WARNING_GCC_POP
1294 return detail::_itoa2buf<T>(buf, radix, num_digits);
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.
auto digits_dec(T v) noexcept-> typename std::enable_if< sizeof(T)==1u, unsigned >::type
decimal digits for 8 bit integers
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
size_t write_hex(substr buf, T val, size_t num_digits) noexcept
same as c4::write_hex(), but pad with zeroes on the left such that the resulting string is num_digits...
size_t write_dec(substr buf, T val, size_t num_digits) noexcept
same as c4::write_dec(), but pad with zeroes on the left such that the resulting string is num_digits...
size_t write_bin(substr buf, T val, size_t num_digits) noexcept
same as c4::write_bin(), but pad with zeroes on the left such that the resulting string is num_digits...
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
size_t write_oct(substr buf, T val, size_t num_digits) noexcept
same as c4::write_oct(), but pad with zeroes on the left such that the resulting string is num_digits...