diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2023-09-21 12:24:25 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2023-09-22 11:43:16 +0200 |
commit | c594e71d5dc122ca2d7254ea6b3ebf8429c3ee49 (patch) | |
tree | 3cd873306baeccc7fb4c61b33835bd6b8ed3fc3b /lib | |
parent | e25184ba656d0b7e2a5b04aeae0e65a838beaff5 (diff) | |
download | barebox-c594e71d5dc122ca2d7254ea6b3ebf8429c3ee49.tar.gz barebox-c594e71d5dc122ca2d7254ea6b3ebf8429c3ee49.tar.xz |
lib: jsmn: add case-insensitive comparison
Users may want to do a case-insensitive comparison of tokens. Add simple
helpers for that.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20230921102426.1109289-3-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/jsmn.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/jsmn.c b/lib/jsmn.c index 3d2ada7b7f..9e624f7518 100644 --- a/lib/jsmn.c +++ b/lib/jsmn.c @@ -418,6 +418,18 @@ JSMN_API bool jsmn_str_eq(const char *str, const char *json, const jsmntok_t *to return token->type == JSMN_STRING && jsmn_eq(str, json, token); } +static bool jsmn_case_eq(const char *val, const char *json, const jsmntok_t *token) +{ + size_t token_size = jsmn_token_size(token); + return strlen(val) == token_size + && strncasecmp(json + token->start, val, token_size) == 0; +} + +JSMN_API bool jsmn_strcase_eq(const char *str, const char *json, const jsmntok_t *token) +{ + return token->type == JSMN_STRING && jsmn_case_eq(str, json, token); +} + JSMN_API const jsmntok_t *jsmn_skip_value(const jsmntok_t *tokens) { int max_index = tokens[0].end; |