Format string refactor

This commit is contained in:
Krzosa Karol
2025-11-27 23:13:28 +01:00
parent e9e8751981
commit d72485a137
24 changed files with 80 additions and 116 deletions

View File

@@ -57,4 +57,6 @@ union Color {
uint8_t a;
};
uint32_t value;
};
};
#define PI32 3.14159265359f

View File

@@ -482,7 +482,7 @@ API void Advance(FileIter *it) {
it->filename = ToString(it->allocator, (char16_t *)data->cFileName, WideLength((char16_t *)data->cFileName));
const char *is_dir = it->is_directory ? "/" : "";
const char *separator = it->path.data[it->path.len - 1] == '/' ? "" : "/";
it->relative_path = Format(it->allocator, "%.*s%s%.*s%s", FmtString(it->path), separator, FmtString(it->filename), is_dir);
it->relative_path = Format(it->allocator, "%S%s%S%s", it->path, separator, it->filename, is_dir);
it->absolute_path = GetAbsolutePath(it->allocator, it->relative_path);
it->is_valid = true;
@@ -504,7 +504,7 @@ API FileIter IterateFiles(Allocator alo, String path) {
it.allocator = alo;
it.path = path;
String modified_path = Format(it.allocator, "%.*s\\*", FmtString(path));
String modified_path = Format(it.allocator, "%S\\*", path);
String16 modified_path16 = ToString16(it.allocator, modified_path);
it.w32 = AllocType(it.allocator, Win32_FileIter);
@@ -672,7 +672,7 @@ static void Win32ReportError(String msg, String cmd) {
char *buff = (char *)lpMsgBuf;
size_t buffLen = strlen((const char *)buff);
if (buffLen > 0 && buff[buffLen - 1] == '\n') buff[buffLen - 1] = 0;
Error("%.*s: %.*s! %s", FmtString(msg), FmtString(cmd), (char *)lpMsgBuf);
Error("%S: %S! %s", msg, cmd, (char *)lpMsgBuf);
}
static void Win32CloseProcess(Process *process) {
@@ -715,7 +715,7 @@ API Process SpawnProcess(String command_line, String working_dir, String write_s
Win32Process *p = (Win32Process *)process.platform;
Scratch scratch;
command_line = Format(scratch, "/C %.*s", FmtString(command_line));
command_line = Format(scratch, "/C %S", command_line);
p->handle = INVALID_HANDLE_VALUE;
p->child_stdout_write = INVALID_HANDLE_VALUE;
@@ -759,6 +759,7 @@ API Process SpawnProcess(String command_line, String working_dir, String write_s
String16 cmd = ToString16(scratch, command_line);
char *env = NULL;
// TODO: FIX ARENA ALLOCATION USING PushSize, Prealloc maybe? Maybe we want a block arena
if (enviroment.len) {
Int size = GetSize(enviroment) + enviroment.len + 1;
env = (char *)PushSize(scratch, size);

View File

@@ -83,7 +83,6 @@ API String Copy(Allocator allocator, char *string);
API void NormalizePathInPlace(String s);
API String NormalizePath(Allocator allocator, String s);
#define FmtString(string) (int)(string).len, (string).data
API String FormatV(Allocator allocator, const char *data, va_list args1);
API String Format(Allocator allocator, const char *data, ...);
#define STRING_FORMAT(allocator, data, result) \

View File

@@ -574,11 +574,6 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
char num[STBSP__NUMSZ];
char lead[8];
char tail[8];
struct stb__string {
char *data;
int64_t len;
} S;
char *s;
char const *h;
stbsp__uint32 l, n, cs;
@@ -588,6 +583,11 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
#endif
stbsp__int32 dp;
char const *sn;
struct stb__string {
char *data;
int64_t len;
};
struct stb__string S;
case 'S':
// get the string
@@ -596,7 +596,8 @@ STBSP__PUBLICDEF int STB_SPRINTF_DECORATE(vsprintfcb)(STBSP_SPRINTFCB *callback,
S.data = (char *)"null";
S.len = 4;
}
l = (unsigned int)S.len;
s = S.data;
l = stbsp__strlen_limited(S.data, ((int)S.len >= 0) ? (int)S.len : ~0u);
lead[0] = 0;
tail[0] = 0;
pr = 0;