mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Merge cf97213334
into f0fc6c50ba
This commit is contained in:
commit
680532a3e7
55
cJSON.c
55
cJSON.c
@ -61,6 +61,26 @@ static int cJSON_strcasecmp(const char *s1, const char *s2)
|
||||
return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
|
||||
}
|
||||
|
||||
static int cJSON_strncasecmp(const char *s1, const char *s2, size_t comparelen)
|
||||
{
|
||||
if (!s1)
|
||||
{
|
||||
return (s1 == s2) ? 0 : 1;
|
||||
}
|
||||
if (!s2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
for (; tolower(*s1) == tolower(*s2); ++s1, ++s2, comparelen--)
|
||||
{
|
||||
if (*s1 == 0 || comparelen == 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return tolower(*(const unsigned char*)s1) - tolower(*(const unsigned char*)s2);
|
||||
}
|
||||
|
||||
static void *(*cJSON_malloc)(size_t sz) = malloc;
|
||||
static void (*cJSON_free)(void *ptr) = free;
|
||||
|
||||
@ -1615,11 +1635,44 @@ cJSON *cJSON_GetObjectItem(cJSON *object, const char *string)
|
||||
return c;
|
||||
}
|
||||
|
||||
int cJSON_HasObjectItem(cJSON *object,const char *string)
|
||||
cJSON *cJSON_GetSizedObjectItem(cJSON *object, const char *string, size_t length)
|
||||
{
|
||||
cJSON *c = object ? object->child : 0;
|
||||
while (c && cJSON_strncasecmp(c->string, string, length))
|
||||
{
|
||||
c = c->next;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
cJSON *cJSON_GetDotObjectItem(cJSON *object, const char *string)
|
||||
{
|
||||
size_t node_name_length;
|
||||
const char *position;
|
||||
|
||||
position = strchr(string, '.');
|
||||
if (position != NULL)
|
||||
{
|
||||
node_name_length = position - string;
|
||||
object = cJSON_GetSizedObjectItem(object, string, node_name_length);
|
||||
return cJSON_GetDotObjectItem(object, position + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return cJSON_GetObjectItem(object, string);
|
||||
}
|
||||
}
|
||||
|
||||
int cJSON_HasObjectItem(cJSON *object, const char *string)
|
||||
{
|
||||
return cJSON_GetObjectItem(object, string) ? 1 : 0;
|
||||
}
|
||||
|
||||
int cJSON_HasDotObjectItem(cJSON *object, const char* string)
|
||||
{
|
||||
return cJSON_GetDotObjectItem(object, string) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* Utility for array list handling. */
|
||||
static void suffix_object(cJSON *prev, cJSON *item)
|
||||
{
|
||||
|
3
cJSON.h
3
cJSON.h
@ -90,7 +90,10 @@ extern int cJSON_GetArraySize(cJSON *array);
|
||||
extern cJSON *cJSON_GetArrayItem(cJSON *array, int item);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
extern cJSON *cJSON_GetObjectItem(cJSON *object, const char *string);
|
||||
extern cJSON *cJSON_GetDotObjectItem(cJSON *object, const char *string);
|
||||
extern int cJSON_HasObjectItem(cJSON *object, const char *string);
|
||||
extern int cJSON_HasDotObjectItem(cJSON *object, const char* string);
|
||||
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
extern const char *cJSON_GetErrorPtr(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user