Commit 88ae9f75 by josé bollo

fix bug in extension

Change-Id: Ib354542b7906128e01c0b00797909bfc337f5467
Signed-off-by: José Bollo <jobol@nonadev.net>
parent 43dc9c45
......@@ -38,23 +38,38 @@ struct expl {
} stack[MAX_DEPTH];
};
static char *keyval(char *head)
{
char *w, c;
c = *(w = head);
while (c && c != '=') {
if (c == '\\' && head[1] == '=')
c = *++head;
*w++ = c;
c = *++head;
}
*w = 0;
return c == '=' ? ++head : NULL;
}
static char *key(char **head)
{
char *r, *i, *w, c;
c = *(i = *head);
if (!c || c == '=')
if (!c)
r = NULL;
else {
r = w = i;
while (c && c != '.' && c != '=') {
if (c == '\\' && (i[1] == '.' || i[1] == '\\' || i[1] == '='))
while (c && c != '.') {
if (c == '\\' && (i[1] == '.' || i[1] == '\\'))
c = *++i;
*w++ = c;
c = *++i;
}
*w = 0;
*head = i + (c == '.');
*head = i + !!c;
}
return r;
}
......@@ -63,9 +78,10 @@ static struct json_object *find(struct expl *e, const char *name)
{
int i;
struct json_object *o;
char *n, *c;
char *n, *c, *v;
n = strdupa(name);
v = keyval(n);
c = key(&n);
o = NULL;
i = e->depth;
......@@ -79,7 +95,7 @@ static struct json_object *find(struct expl *e, const char *name)
return NULL;
c = key(&n);
}
if (*n == '=' && strcmp(++n, json_object_get_string(o)))
if (v && strcmp(v, json_object_get_string(o)))
return NULL;
return o;
}
......
{
"person": { "name": "Jon", "age": 25 },
"person.name": "!is it really valid?!"
"person.name": "Fred",
"person.name=Fred": "The other Fred."
}
This are extensions!!
{{person.name}}
{{person.age}}
{{person\.name}}
{{person\.name\=Fred}}
{{#person.name=Jon}}
Hello Jon
{{/person.name=Jon}}
{{^person.name=Jon}}
No Jon? Hey Jon...
{{/person.name=Jon}}
{{^person.name=Harry}}
No Harry? Hey Calahan...
{{/person.name=Harry}}
{{#person\.name=Fred}}
Hello Fred
{{/person\.name=Fred}}
{{^person\.name=Fred}}
No Fred? Hey Fred...
{{/person\.name=Fred}}
{{#person\.name\=Fred=The other Fred.}}
Hello Fred#2
{{/person\.name\=Fred=The other Fred.}}
{{^person\.name\=Fred=The other Fred.}}
No Fred#2? Hey Fred#2...
{{/person\.name\=Fred=The other Fred.}}
This are extensions!!
Jon
25
!is it really valid?!
Fred
The other Fred.
Hello Jon
No Harry? Hey Calahan...
Hello Fred
Hello Fred#2
......@@ -6,7 +6,7 @@ Command: ../mustach json must
HEAP SUMMARY:
in use at exit: 0 bytes in 0 blocks
total heap usage: 31 allocs, 31 frees, 7,119 bytes allocated
total heap usage: 35 allocs, 35 frees, 7,808 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