X-Git-Url: https://git.librecmc.org/?p=oweals%2Fjsonpath.git;a=blobdiff_plain;f=matcher.c;h=ceb756e66573679840f4900dbc2ac7a064afa157;hp=51e0e3c700002318067d714f253f1bee7cc134fc;hb=691f1065ad33b5d53d342e8705a37563d9ebb8b5;hpb=c95f8d8ed4035cdbebfdfb1ff0c94e3958f3ebb9 diff --git a/matcher.c b/matcher.c index 51e0e3c..ceb756e 100644 --- a/matcher.c +++ b/matcher.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 Jo-Philipp Wich + * Copyright (C) 2013-2014 Jo-Philipp Wich * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,6 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "parser.h" #include "matcher.h" static struct json_object * @@ -236,7 +237,8 @@ jp_match_next(struct jp_opcode *ptr, 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) { @@ -256,7 +258,13 @@ jp_match_next(struct jp_opcode *ptr, break; case T_NUMBER: - next = json_object_array_get_idx(cur, ptr->num); + idx = ptr->num; + + 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);