Support itoa with 0

This commit is contained in:
jaby 2024-01-03 10:10:27 -06:00
parent d7a5efb362
commit 7bc901355f
1 changed files with 7 additions and 0 deletions

View File

@ -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') {