[PATCH v6 4/4] lib: introduce json_path_cmp, json_path_validate
Vladimir Davydov
vdavydov.dev at gmail.com
Mon Dec 10 20:38:00 MSK 2018
On Thu, Dec 06, 2018 at 11:42:31AM +0300, Kirill Shcherbatov wrote:
> Introduced json_path_validate routine to ensure user-defined
> JSON path is valid. This will be required to raise an error if
> an incorrect user-defined jason-path is detected.
>
> Introduced json_path_cmp routine to compare JSON paths that may
> have different representation.
> Note that:
> - in case of paths that have same token-sequence prefix,
> the path having more tokens is assumed to be greater
> - both paths to compare should be valid
>
> Needed for #1012
> +/**
> + * Check if the passed JSON path is valid.
> + * Return 0 for valid path and error position for invalid.
> + */
> +static inline int
> +json_path_validate(const char *path, uint32_t path_len, uint32_t index_base)
> +{
> + struct json_lexer lexer;
> + json_lexer_create(&lexer, path, path_len, index_base);
> + struct json_token token;
> + int rc;
> + while ((rc = json_lexer_next_token(&lexer, &token)) == 0 &&
> + token.type != JSON_TOKEN_END) {};
> + return rc;
> +}
No need to define this function in the header. I moved it to json.c and
pushed the patch to 2.1.
More information about the Tarantool-patches
mailing list