|
#ifndef UTIL_INTEGER_TO_STRING_H |
|
#define UTIL_INTEGER_TO_STRING_H |
|
#include <cstddef> |
|
#include <stdint.h> |
|
|
|
namespace util { |
|
|
|
|
|
|
|
char *ToString(uint32_t value, char *to); |
|
char *ToString(uint64_t value, char *to); |
|
|
|
|
|
char *ToString(int32_t value, char *to); |
|
char *ToString(int64_t value, char *to); |
|
|
|
|
|
char *ToString(uint16_t value, char *to); |
|
char *ToString(int16_t value, char *to); |
|
|
|
char *ToString(const void *value, char *to); |
|
|
|
inline char *ToString(bool value, char *to) { |
|
*to++ = '0' + value; |
|
return to; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <class T> struct ToStringBuf; |
|
template <> struct ToStringBuf<bool> { |
|
enum { kBytes = 1 }; |
|
}; |
|
template <> struct ToStringBuf<uint16_t> { |
|
enum { kBytes = 5 }; |
|
}; |
|
template <> struct ToStringBuf<int16_t> { |
|
enum { kBytes = 6 }; |
|
}; |
|
template <> struct ToStringBuf<uint32_t> { |
|
enum { kBytes = 10 }; |
|
}; |
|
template <> struct ToStringBuf<int32_t> { |
|
enum { kBytes = 11 }; |
|
}; |
|
template <> struct ToStringBuf<uint64_t> { |
|
enum { kBytes = 20 }; |
|
}; |
|
template <> struct ToStringBuf<int64_t> { |
|
|
|
enum { kBytes = 20 }; |
|
}; |
|
|
|
template <> struct ToStringBuf<const void*> { |
|
|
|
enum { kBytes = sizeof(const void*) * 2 + 2 }; |
|
}; |
|
|
|
|
|
enum { kToStringMaxBytes = 20 }; |
|
|
|
} |
|
|
|
#endif |
|
|