#ifndef STR8_H #define STR8_H #include "aliases.h" #include #ifdef __cplusplus BEGIN_C_LINKAGE #endif // !__cplusplus typedef struct str8 Str8; struct str8 { u64 capacity; u64 size; c8 *buf; }; typedef const Str8 Str8RO; #define wapp_str8_buf(CAPACITY) ((Str8){.capacity = CAPACITY, .size = 0, .buf = (c8[CAPACITY]){0}}) // Utilises the fact that memcpy returns pointer to dest buffer and that getting // address of compound literals is valid in C to create a string on the stack #define wapp_str8_lit(STRING) ((Str8){.capacity = (sizeof(STRING) - 1) * 2, \ .size = sizeof(STRING) - 1, \ .buf = memcpy(&((c8 [sizeof(STRING) * 2]){0}), STRING, sizeof(STRING))}) #define wapp_str8_lit_ro(STRING) ((Str8RO){.capacity = sizeof(STRING) - 1, \ .size = sizeof(STRING) - 1, \ .buf = (c8 *)STRING}) c8 wapp_str8_get(Str8RO *str, u64 index); void wapp_str8_set(Str8 *str, u64 index, c8 c); #ifdef __cplusplus END_C_LINKAGE #endif // !__cplusplus #endif // !STR8_H