2019-06-01 23:58:28 +00:00
|
|
|
/*
|
|
|
|
* Printf style operations for strings and what-not
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2019-10-05 02:48:05 +00:00
|
|
|
#if !defined(FCODER_STRINGF_CPP)
|
|
|
|
#define FCODER_STRINGF_CPP
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
static String_Const_char
|
2019-06-18 22:56:09 +00:00
|
|
|
push_stringfv(Arena *arena, char *format, va_list args){
|
2019-12-14 01:00:55 +00:00
|
|
|
va_list args2;
|
|
|
|
va_copy(args2, args);
|
2019-06-01 23:58:28 +00:00
|
|
|
i32 size = vsnprintf(0, 0, format, args);
|
|
|
|
String_Const_char result = string_const_char_push(arena, size + 1);
|
2019-12-18 03:38:08 +00:00
|
|
|
vsnprintf(result.str, (size_t)result.size, format, args2);
|
2019-06-01 23:58:28 +00:00
|
|
|
result.size -= 1;
|
|
|
|
result.str[result.size] = 0;
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
static String_Const_char
|
2019-06-18 22:56:09 +00:00
|
|
|
push_stringf(Arena *arena, char *format, ...){
|
2019-06-01 23:58:28 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_char result = push_stringfv(arena, format, args);
|
2019-06-01 23:58:28 +00:00
|
|
|
va_end(args);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
static String_Const_u8
|
2019-06-18 22:56:09 +00:00
|
|
|
push_u8_stringfv(Arena *arena, char *format, va_list args){
|
|
|
|
return(SCu8(push_stringfv(arena, format, args)));
|
2019-06-01 23:58:28 +00:00
|
|
|
}
|
|
|
|
static String_Const_u8
|
2019-06-18 22:56:09 +00:00
|
|
|
push_u8_stringf(Arena *arena, char *format, ...){
|
2019-06-01 23:58:28 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_u8 result = SCu8(push_stringfv(arena, format, args));
|
2019-06-01 23:58:28 +00:00
|
|
|
va_end(args);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
string_list_pushfv(Arena *arena, List_String_Const_char *list, char *format, va_list args){
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_char string = push_stringfv(arena, format, args);
|
2019-12-18 03:38:08 +00:00
|
|
|
if (arena->alignment < sizeof(u64)){
|
|
|
|
push_align(arena, sizeof(u64));
|
2019-06-01 23:58:28 +00:00
|
|
|
}
|
|
|
|
string_list_push(arena, list, string);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
string_list_pushf(Arena *arena, List_String_Const_char *list, char *format, ...){
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
string_list_pushfv(arena, list, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
string_list_pushfv(Arena *arena, List_String_Const_u8 *list, char *format, va_list args){
|
2019-06-18 22:56:09 +00:00
|
|
|
String_Const_u8 string = push_u8_stringfv(arena, format, args);
|
2019-12-18 03:38:08 +00:00
|
|
|
if (arena->alignment < sizeof(u64)){
|
|
|
|
push_align(arena, sizeof(u64));
|
2019-06-01 23:58:28 +00:00
|
|
|
}
|
|
|
|
string_list_push(arena, list, string);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
string_list_pushf(Arena *arena, List_String_Const_u8 *list, char *format, ...){
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
string_list_pushfv(arena, list, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2019-10-05 02:48:05 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-01 23:58:28 +00:00
|
|
|
// BOTTOM
|
|
|
|
|