From d1d6a8e64be64fa738d78963bc86a890c1bcbab4 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sun, 9 Feb 2025 15:13:50 +0000 Subject: [PATCH] Add utils for str8 printing --- src/core/strings/str8/str8.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/strings/str8/str8.h b/src/core/strings/str8/str8.h index 523006d..8557db0 100644 --- a/src/core/strings/str8/str8.h +++ b/src/core/strings/str8/str8.h @@ -17,12 +17,16 @@ struct str8 { typedef const Str8 Str8RO; +// Utilities to be used with printf functions +#define WAPP_STR8_SPEC "%.*s" +#define wapp_str8_varg(STRING) (int)STRING.size, STRING.buf + #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, \ + .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, \