From 62beed20a96c1714afa30920c8fbc72606f8a251 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 6 May 2025 09:29:21 -0400 Subject: [PATCH] minor --- demo.str_cache.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/demo.str_cache.c b/demo.str_cache.c index e7b2090..d965b3b 100644 --- a/demo.str_cache.c +++ b/demo.str_cache.c @@ -1074,7 +1074,7 @@ Str8 fmt_vtoken_slice(SliceMem buffer, SliceFmtTokEntry tokens, Str8 fmt_templat // Sync cursor format to after the processed token cursor_fmt = cursor_potential_token + potential_token_length + 1; curr_code = * cursor_fmt; - left_fmt -= potential_token_length + 2; // The 2 here ar ethe '<' & '>' delimiters being omitted. + left_fmt -= potential_token_length + 2; // The 2 here are the '<' & '>' delimiters being omitted. continue; } @@ -1116,16 +1116,27 @@ Str8 fmt__vtoken(SliceMem backing, Str8 fmt_template, SliceStr8* tokens) return result; } -#define fmt_vtoken(backing, fmt_template, tokens) fmt__vtoken(backing, fmt_template, &(SliceStr8){.ptr = tokens, .len = size_of(tokens) / size_of(Str8) }) +// Expected to take a Str8 array of entries formatted as a 2D array of key-value pairs (Str8[length][2]) +// The array will be tracked using a SliceStr8 structure. +#define fmt_vtoken(backing, fmt_template, tokens) fmt__vtoken(backing, fmt_template, &(SliceStr8){.ptr = cast(Str8*, tokens), .len = size_of(tokens) / size_of(Str8) }) + +/* +Define a mapping array: +Str8 mappings [][2] = { + fmt_vtoken_entry("key", "value"), + ^^ Add entries as above ^^ +} +*/ +#define fmt_vtoken_entry(key, value) { lit(key), lit(value) } #ifdef DEMO__WATL_DUMP_V1 int main() { SliceMem scratch = slicemem_alloc(MEGABYTES(64)); - Str8 mappings [] = { - lit("maybe_sub"), lit("IT SUBST!!!!"), + Str8 subst_table [][2] = { + fmt_vtoken_entry("maybe_sub", "IT SUBST!!!"), }; - Str8 test_str = fmt_vtoken(scratch, lit("Will this work? "), mappings); + Str8 test_str = fmt_vtoken(scratch, lit("Will this work? "), subst_table); return 0; } #endif