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

Adds the not-matching extension

Also updates the documentation
Signed-off-by: josé bollo's avatarJosé Bollo <>
parent f3194477
......@@ -25,4 +25,58 @@ The tool **mustach** is build using Makefile. Its usage is:
and it prints the result of applying the templates files to the json file.
By default, the current implementation provide the following extensions.
Explicit substitution
This is a core extension implemented in file **mustach.c**.
In somecases the name of the key used for substition begins with a
character reserved for mustach: one of '#', '^', '/', '&', '{', '>' and '='.
This extension introduces the special character ':' to explicitely
tell mustach to just substitute the value. So ':' becomes a new special
Test of the value
This is a tool extension implmented in file **mustach-json-c.c**.
This extension allows to test the value of the selected key.
It is allowed to write key=value (matching test) or key=!value
(not matching test) in any query.
Removing extensions
When compiling mustach.c or mustach-json-c.c,
extensions can be removed by defining macros
using option -D.
The possible macros are:
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 :#^/&{=<
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.
This macro disables any current or futur
......@@ -102,8 +102,11 @@ static struct json_object *find(struct expl *e, const char *name)
return NULL;
c = key(&n);
if (v && strcmp(v, json_object_get_string(o)))
return NULL;
if (v) {
i = v[0] == '!';
if (i == !strcmp(&v[i], json_object_get_string(o)))
o = NULL;
return o;
"person": { "name": "Jon", "age": 25 },
"": "Fred",
"": "The other Fred."
"": "The other Fred.",
"persons": [
{ "name": "Jon", "age": 25, "lang": "en" },
{ "name": "Henry", "age": 27, "lang": "en" },
{ "name": "Amed", "age": 24, "lang": "fr" } ]
......@@ -34,4 +34,11 @@ Hello Fred#2
No Fred#2? Hey Fred#2...
{{/person\.name\=Fred=The other Fred.}}
{{#lang=!fr}}Hello {{name}}, {{age}} years{{/lang=!fr}}
{{#lang=fr}}Salut {{name}}, {{age}} ans{{/lang=fr}}
{{name}}: {{age=24}}/{{age}}/{{age=!27}}
......@@ -29,3 +29,20 @@ Hello Fred#2
Hello Jon, 25 years
Hello Henry, 27 years
Salut Amed, 24 ans
Jon: /25/25
Henry: /27/
Amed: 24/24/24
......@@ -6,7 +6,7 @@ Command: ../mustach json must
in use at exit: 0 bytes in 0 blocks
total heap usage: 35 allocs, 35 frees, 7,808 bytes allocated
total heap usage: 88 allocs, 88 frees, 11,448 bytes allocated
All heap blocks were freed -- no leaks are possible
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