common: generalize json_tok_remove.

It assumes the head of the array is the object/array we want to remove from,
but that's not true if we're trying to remove from a sub-object.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2019-07-26 11:53:47 +09:30
parent 7b1088a235
commit b03369ea2d
4 changed files with 57 additions and 23 deletions

View File

@@ -75,10 +75,11 @@ void json_tok_print(const char *buffer, const jsmntok_t *params);
jsmntok_t *json_tok_copy(const tal_t *ctx, const jsmntok_t *tok);
/*
* Remove @num json values from a json array or object. @tok points
* to the first value to remove. The array will be resized.
* Remove @num json values from a json array or object @obj. @tok points
* to the first value to remove. The array @tokens will be resized.
*/
void json_tok_remove(jsmntok_t **tokens, jsmntok_t *tok, size_t num);
void json_tok_remove(jsmntok_t **tokens,
jsmntok_t *obj_or_array, const jsmntok_t *tok, size_t num);
/* Guide is a string with . for members, [] around indexes. */
const jsmntok_t *json_delve(const char *buffer,