#include "base/base_strings.h"
#include "base/base_arena.h"

Str8 str8_pushf(Arena *arena, const char *fmt, ...) {
    va_list args, args2;
    va_start(args, fmt);
    va_copy(args2, args);
    S32 len = vsnprintf(nullptr, 0, fmt, args);
    va_end(args);

    char *buf = push_array(arena, char, len + 1);
    vsnprintf(buf, len + 1, fmt, args2);
    va_end(args2);

    return {buf, (U64)len};
}

Str8 str8_push_copy(Arena *arena, Str8 s) {
    if (s.size == 0 || !s.str) return {nullptr, 0};
    char *buf = push_array_no_zero(arena, char, s.size + 1);
    MemoryCopy(buf, s.str, s.size);
    buf[s.size] = 0;
    return {buf, s.size};
}

void str8_list_push(Arena *arena, Str8List *list, Str8 s) {
    Str8Node *node = push_array(arena, Str8Node, 1);
    node->string = s;
    SLLQueuePush(list->first, list->last, node);
    list->count++;
    list->total_size += s.size;
}
