Support itoa with 0
This commit is contained in:
parent
6c086da65c
commit
7ea8fc0e52
|
@ -7,10 +7,17 @@
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
static constexpr auto ITOABufferSize = 32;
|
static constexpr auto ITOABufferSize = 32;
|
||||||
|
|
||||||
|
// Can we not find a better version of this?
|
||||||
static char* simple_itoa(char (&buffer)[ITOABufferSize], bool is_neg, uint32_t value, uint32_t base) {
|
static char* simple_itoa(char (&buffer)[ITOABufferSize], bool is_neg, uint32_t value, uint32_t base) {
|
||||||
// v terminating 0 and space for sign
|
// v terminating 0 and space for sign
|
||||||
int i = ITOABufferSize - 2;
|
int i = ITOABufferSize - 2;
|
||||||
|
|
||||||
|
if(value == 0) {
|
||||||
|
buffer[0] = '0';
|
||||||
|
buffer[1] = '\0';
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
for(; value && i; i--, value /= base) {
|
for(; value && i; i--, value /= base) {
|
||||||
char chr = '0' + value%base;
|
char chr = '0' + value%base;
|
||||||
if(chr > '9') {
|
if(chr > '9') {
|
||||||
|
|
Loading…
Reference in New Issue