-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring.hpp
48 lines (41 loc) · 805 Bytes
/
string.hpp
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
41
42
43
44
45
46
47
48
#pragma once
#include <cstdint>
namespace string {
template <typename T>
inline void hex(T * c, uint32_t len, uint32_t n)
{
while (len > 0) {
uint32_t nib = n & 0xf;
n = n >> 4;
if (nib > 9) {
nib += (97 - 10);
} else {
nib += (48 - 0);
}
c[--len] = nib;
}
}
template <typename T>
inline void dec(T * c, uint32_t len, uint32_t n)
{
while (len > 0) {
const uint32_t digit = n % 10;
n = n / 10;
c[--len] = digit + 48;
}
}
struct hex_type {
template <typename T>
static void render(T * c, uint32_t len, uint32_t n)
{
hex<T>(c, len, n);
}
};
struct dec_type {
template <typename T>
static void render(T * c, uint32_t len, uint32_t n)
{
dec<T>(c, len, n);
}
};
}