From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 10 Dec 2018 20:38:00 +0300 From: Vladimir Davydov Subject: Re: [PATCH v6 4/4] lib: introduce json_path_cmp, json_path_validate Message-ID: <20181210173800.2eehyutqzcm5kt2j@esperanza> References: <7e8a84a863de29269e0731f3dcff2df90ed6813e.1544084229.git.kshcherbatov@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7e8a84a863de29269e0731f3dcff2df90ed6813e.1544084229.git.kshcherbatov@tarantool.org> To: Kirill Shcherbatov Cc: tarantool-patches@freelists.org, kostja@tarantool.org List-ID: 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.