This commit is contained in:
PedroEdiaz
2025-06-19 01:42:08 -06:00
parent 65c6a901d2
commit 774d1fd8eb
2 changed files with 41 additions and 15 deletions

View File

@@ -21,13 +21,13 @@ A new string with all placeholders replaced by their corresponding values from
the dictionary. If a key is missing in the dictionary, the placeholder is
replaces with an empty string.
*/
mustache_string :: proc(fmt: string, v: any ) -> string {
mustache_string :: proc(fmt: string, v: any , end_block: string = "") -> string {
r : strings.Reader
strings.reader_init(&r, fmt)
return mustache(&r, v, "")
return mustache(&r, v, end_block)
}
mustache_reader :: proc(r: ^strings.Reader, v: any, end_block: string ) -> string {
mustache_reader :: proc(r: ^strings.Reader, v: any, end_block: string = "" ) -> string {
/*
template works as a state machine, it manipulates `b` (returned string)
and `key` (placeholder string), according to the states. No error
@@ -82,6 +82,8 @@ mustache_reader :: proc(r: ^strings.Reader, v: any, end_block: string ) -> strin
}
case '#':
strings.write_string(&b, section(r, v, skey[1:]) )
case '^':
strings.write_string(&b, section(r, v, skey[1:], true) )
case:
strings.write_string(&b, decode_string(v, skey) )
}