[core] add the ability to stringy numbers as hex

This commit is contained in:
Konstantin Käfer
2018-10-17 15:56:55 +02:00
parent 43687b4781
commit eb828dfd29
3 changed files with 32 additions and 0 deletions

View File

@@ -15,6 +15,25 @@ std::string toString(double num, bool decimal) {
std::string toString(long double num, bool decimal) {
return dtoa(num, decimal);
}
namespace {
template <typename T>
std::string toPaddedHex(T x) {
std::string result;
result.resize(sizeof(T) * 2);
for (int index = sizeof(T) * 2 - 1; index >= 0; index--) {
const int digit = x & 0x0F;
result[index] = '0' + digit + (digit > 9 ? 39 : 0);
x >>= 4;
}
return result;
}
}
std::string toHex(size_t value) {
return toPaddedHex(value);
}
} // namespace util