Implement itoa
This commit is contained in:
@@ -4,6 +4,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
namespace JabyEngine {
|
||||
static const char* simple_itoa(char (&buffer)[32], int value, int base) {
|
||||
const bool is_neg = value < 0;
|
||||
int i = 32 - 2;
|
||||
|
||||
if(is_neg) {
|
||||
value *= -1;
|
||||
}
|
||||
|
||||
for(; value && i; i--, value /= base) {
|
||||
char chr = '0' + value%base;
|
||||
if(chr > '9') {
|
||||
chr += ('A' - '9');
|
||||
}
|
||||
buffer[i] = chr;
|
||||
}
|
||||
|
||||
buffer[32 - 1] = '\0';
|
||||
if(is_neg) {
|
||||
buffer[i] = '-';
|
||||
return &buffer[i];
|
||||
}
|
||||
return &buffer[i+1];
|
||||
}
|
||||
|
||||
void FontWriter :: setup(const FontBufferInfo& buffer_info, const SimpleTIM& vram_dst, const GPU::SizeI16& font_size) {
|
||||
this->prim_buffer = buffer_info;
|
||||
this->tex_page = Make::TexPage(vram_dst.get_texture_position(), GPU::TexturePageColor::$4bit).linked();
|
||||
@@ -39,12 +63,19 @@ namespace JabyEngine {
|
||||
state.pos.move(primitive->size.width, 0);
|
||||
return true;
|
||||
};
|
||||
const auto old_x = state.pos.x;
|
||||
const auto old_x = state.pos.x;
|
||||
const char* prev_str = nullptr;
|
||||
char buffer[32];
|
||||
|
||||
while(true) {
|
||||
const auto cur_char = *str++;
|
||||
auto cur_char = *str++;
|
||||
switch(cur_char) {
|
||||
case '\0':
|
||||
if(prev_str) {
|
||||
str = prev_str;
|
||||
prev_str = nullptr;
|
||||
continue;
|
||||
}
|
||||
return;
|
||||
|
||||
case '\n':
|
||||
@@ -56,6 +87,18 @@ namespace JabyEngine {
|
||||
state.pos.x += font_size.width;
|
||||
continue;
|
||||
|
||||
case '%':
|
||||
switch(*str) {
|
||||
case 'i':
|
||||
prev_str = str + 1;
|
||||
str = simple_itoa(buffer, -505, 10);
|
||||
continue;
|
||||
|
||||
case '%':
|
||||
str++;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
auto& primitive = *this->cur_primitive++;
|
||||
if(!push_char(state, primitive, cur_char)) {
|
||||
|
Reference in New Issue
Block a user