This commit is contained in:
Edward R. Gonzalez 2025-05-06 09:29:21 -04:00
parent f87a098fe4
commit 62beed20a9

View File

@ -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? <maybe_sub>"), mappings);
Str8 test_str = fmt_vtoken(scratch, lit("Will this work? <maybe_sub>"), subst_table);
return 0;
}
#endif