39 int n, size =
sizeof(buf);
45 n = vsnprintf(p, size, fmt, ap);
48 if (n > -1 && n < size)
56 p = (
char *)(p == buf ? malloc(size) : realloc(p, size));
71 char const *
const digits =
"0123456789";
74 char buf[30], *p = buf, *p0 = buf;
88 else for (; num != 0; num /= 10) {
89 *p++ = digits[num % 10];
92 if (num >= 10 && ndigits % 3 == 0)
96 int len = ndigits + (ndigits - 1) / 3;
97 std::reverse(p0, p0 + len);
99 return String(buf, len + p0 - buf);
103 format_bytes(
size_t n,
const void *buf,
size_t len,
const char *trailer) {
106 return String((
char *)buf, len);
108 String out((
char *)buf, n);
115 const char NumericFormatterDigits::DIGITS[] =
116 "0001020304050607080910111213141516171819"
117 "2021222324252627282930313233343536373839"
118 "4041424344454647484950515253545556575859"
119 "6061626364656667686970717273747576777879"
120 "8081828384858687888990919293949596979899";
String format_number(int64_t n, int sep)
Return decimal number string separated by a separator (default: comma) for every 3 digits...
std::string String
A String is simply a typedef to std::string.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
String format_bytes(size_t n, const void *buf, size_t len, const char *trailer)
Return first n bytes of buffer with an optional trailer if the size of the buffer exceeds n...
Compatibility Macros for C/C++.
A String class based on std::string.