summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-10-17 15:56:55 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-10-23 12:23:40 +0200
commiteb828dfd2959f85191a452ced1532d39f6473ccb (patch)
treee44d1512b892ec88064fdfd4865cc61252018123 /src
parent43687b4781cdcd7c4e299dc625263bc3982a529f (diff)
downloadqtlocation-mapboxgl-eb828dfd2959f85191a452ced1532d39f6473ccb.tar.gz
[core] add the ability to stringy numbers as hex
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/util/string.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mbgl/util/string.cpp b/src/mbgl/util/string.cpp
index b20b3fb7ed..06ccb56968 100644
--- a/src/mbgl/util/string.cpp
+++ b/src/mbgl/util/string.cpp
@@ -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