Generalized the handlebars code.

This commit is contained in:
2021-08-05 10:03:47 -07:00
parent def6df8865
commit 2449c05fb0
7 changed files with 151 additions and 97 deletions

24
src/util/string.h Normal file
View File

@ -0,0 +1,24 @@
// Copyright (c) 2021 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include <dawn/dawn.h>
/**
* Replaces handlebars within the string with items from the list of variables.
* Output of replacement is stored in the buffer provided. Handlebars within the
* string should be in the format of; "{{ key }}", spaces within the bars will
* be skipped. Variable keys cannot exceed STRING_HANDLEBAR_KEY_MAXLENGTH in
* length.
*
* @param string String to parse.
* @param variables Variables to use in the parsing.
* @param variableCount How many variables in the array.
* @param buffer Buffer to write characters in to.
* @return The count of characters that were written to the buffer.
*/
int32_t stringHandlebarsBuffer(char *source,
stringhandlebarvariable_t *variables, int32_t variableCount, char *buffer
);