8 char *itoa(int i
, char *a
, int radix
)
11 case 10: sprintf(a
, "%d", i
); break;
12 case 16: sprintf(a
, "%x", i
); break;
17 int _wtoi(const wchar_t *w
)
20 return wcstol(w
, &endptr
, 10);
23 int64_t _wtoi64(const wchar_t *w
)
26 return wcstoll(w
, &endptr
, 10);
29 char * _i64toa(int64_t i
, char *a
, int radix
)
32 case 10: sprintf(a
, "%lld", (long long)i
); break;
33 case 16: sprintf(a
, "%llx", (long long)i
); break;
38 wchar_t * _i64tow(int64_t i
, wchar_t *w
, int radix
)
53 for (int64_t j
= i
; j
; j
/= radix
) ++w
;
55 for (; i
; i
/= radix
) {
56 unsigned int d
= i
% radix
;
58 if (d
<=9) *w
= d
+ '0';
59 else *w
= d
- 10 + 'a';
66 wchar_t * _itow(int i
, wchar_t *w
, int radix
)
80 for (int j
= i
; j
; j
/= radix
) ++w
;
82 for (; i
; i
/= radix
) {
83 unsigned int d
= i
% radix
;
85 if (d
<=9) *w
= d
+ '0';
86 else *w
= d
- 10 + 'a';
94 unsigned long HexToULong(const char *str
, size_t maxlen
, size_t *pos
)
96 unsigned long out
= 0;
98 for (i
= pos
? *pos
: 0; i
< maxlen
; ++i
) {
99 unsigned char x
= ParseHexDigit(str
[i
]);
104 out
|= (unsigned long)x
;
113 unsigned long DecToULong(const char *str
, size_t maxlen
, size_t *pos
)
115 unsigned long out
= 0;
117 for (i
= pos
? *pos
: 0; i
< maxlen
; ++i
) {
118 const auto ch
= str
[i
];
119 if (ch
< '0' || ch
> '9') {
131 long DecToLong(const char *str
, size_t maxlen
, size_t *pos
)
133 const bool minus
= maxlen
&& *str
== '-';
134 long out
= DecToULong(minus
? str
+ 1 : str
, minus
? maxlen
- 1 : maxlen
, pos
);
144 bool IsHexaDecimalNumberStr(const char *str
)
151 if ((*str
< '0' || *str
> '9')
152 && (*str
< 'a' || *str
> 'f')
153 && (*str
< 'A' || *str
> 'F')) {
161 char MakeHexDigit(const unsigned char c
)
168 return 'a' + (c
- 0xa);
175 static void AppendHex(std::string
&s
, uint64_t v
)
182 const size_t prev_sz
= s
.size();
184 for (uint64_t tmp
= v
; tmp
; tmp
/= 16) {
187 s
.resize(prev_sz
+ i
);
188 for (uint64_t tmp
= v
; tmp
; tmp
/= 16) {
190 s
[prev_sz
+ i
] = MakeHexDigit((unsigned char)(tmp
% 16));
194 std::string
ToHex(uint64_t v
)
201 std::string
ToPrefixedHex(uint64_t v
, const char *prefix
)
203 std::string
s(prefix
);