summaryrefslogtreecommitdiff
path: root/src/mbgl/util/string.cpp
blob: 06ccb5696882196ddd67ada9f1fe39d443defb94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <mbgl/util/string.hpp>
#include <mbgl/util/dtoa.hpp>

namespace mbgl {
namespace util {

std::string toString(float num, bool decimal) {
    return dtoa(num, decimal);
}

std::string toString(double num, bool decimal) {
    return dtoa(num, 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
} // namespace mbgl