From: Olaf Wintermann Date: Tue, 11 Jan 2022 18:36:28 +0000 (+0100) Subject: add json string compare functions X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/commitdiff_plain/61cf31c92d4ee4956f5c443f83e4774d70605f1b add json string compare functions --- diff --git a/application/json.c b/application/json.c index 4dd672c..5099d9b 100644 --- a/application/json.c +++ b/application/json.c @@ -885,3 +885,20 @@ void json_value_free(JSONValue *value) { } free(value); } + +int json_strcmp(JSONValue *jsstr, const char *str) { + return json_strncmp(jsstr, str, strlen(str)); +} + +int json_strncmp(JSONValue *jsstr, const char *str, size_t slen) { + if(jsstr->type != JSON_STRING) { + return -1; + } + size_t jsstrlen = jsstr->value.string.length; + + if(jsstrlen != slen) { + return jsstrlen > slen ? 1 : -1; + } + + return memcmp(jsstr, jsstr->value.string.string, slen); +} diff --git a/application/json.h b/application/json.h index 659c7f6..0731cca 100644 --- a/application/json.h +++ b/application/json.h @@ -206,6 +206,9 @@ JSONValue* json_array_get(JSONArray *array, size_t i); void json_value_free(JSONValue *value); +int json_strcmp(JSONValue *jsstr, const char *str); +int json_strncmp(JSONValue *jsstr, const char *str, size_t slen); + #ifdef __cplusplus } #endif