Commit f3194477 authored by josé bollo's avatar josé bollo

Adds a compilation option to remove extensions

When compiling mustach.c or mustach-json-c.c,
extensions can be removed by defining macros
using option -D.

The possible macros are:

- NO_COLON_EXTENSION_FOR_MUSTACH

    This macro remove the ability to use colon (:)
    as explicit command for variable substituion.
    This extension allows to have name starting
    with one of the mustach character :#^/&{=

- NO_EQUAL_VALUE_EXTENSION_FOR_MUSTACH

    This macro allows the tool to check the whether
    the actual value is equal to an expected value.
    This is useful in {{#key=val}} or {{^key=val}}
    with the corresponding {{/key=val}}.
    It can also be used in {{key=val}} but this
    doesn't seem to be useful.

- NO_EXTENSION_FOR_MUSTACH

    This macro disables any current or futur
    extension.
Signed-off-by: josé bollo's avatarJosé Bollo <jobol@nonadev.net>
parent 2cec0f1f
......@@ -38,6 +38,7 @@ struct expl {
} stack[MAX_DEPTH];
};
#if !defined(NO_EXTENSION_FOR_MUSTACH) && !defined(NO_EQUAL_VALUE_EXTENSION_FOR_MUSTACH)
static char *keyval(char *head)
{
char *w, c;
......@@ -52,6 +53,7 @@ static char *keyval(char *head)
*w = 0;
return c == '=' ? ++head : NULL;
}
#endif
static char *key(char **head)
{
......@@ -81,7 +83,10 @@ static struct json_object *find(struct expl *e, const char *name)
char *n, *c, *v;
n = strdupa(name);
v = NULL;
#if !defined(NO_EXTENSION_FOR_MUSTACH) && !defined(NO_EQUAL_VALUE_EXTENSION_FOR_MUSTACH)
v = keyval(n);
#endif
c = key(&n);
if (c == NULL)
return NULL;
......
......@@ -104,7 +104,9 @@ static int process(const char *template, struct mustach_itf *itf, void *closure,
case '/':
case '&':
case '>':
#if !defined(NO_EXTENSION_FOR_MUSTACH) && !defined(NO_COLON_EXTENSION_FOR_MUSTACH)
case ':':
#endif
beg++; len--;
default:
while (len && isspace(beg[0])) { beg++; len--; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment