/*
- * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
+ * Copyright (C) 2013-2014 Jo-Philipp Wich <jo@mein.io>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "parser.h"
#include "matcher.h"
static struct json_object *
return true;
case T_OR:
+ case T_UNION:
for (sop = op->down; sop; sop = sop->sibling)
if (jp_expr(sop, root, cur, idx, key, cb, priv))
return true;
struct json_object *root, struct json_object *cur,
jp_match_cb_t cb, void *priv)
{
- struct json_object *next;
+ int idx;
+ struct json_object *next = NULL;
if (!ptr)
{
break;
case T_NUMBER:
- next = json_object_array_get_idx(cur, ptr->num);
+ if (json_object_get_type(cur) == json_type_array)
+ {
+ idx = ptr->num;
- if (next)
- return jp_match_next(ptr->sibling, root, next, cb, priv);
+ if (idx < 0)
+ idx += json_object_array_length(cur);
+
+ if (idx >= 0)
+ next = json_object_array_get_idx(cur, idx);
+
+ if (next)
+ return jp_match_next(ptr->sibling, root, next, cb, priv);
+ }
break;