mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
Add compare_pointers: Configurable case sensitivity
This commit is contained in:
parent
30906a01c0
commit
2f33e8ec9b
@ -80,7 +80,7 @@ static int compare_strings(const unsigned char *string1, const unsigned char *st
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
|
/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
|
||||||
static cJSON_bool case_insensitive_pointer_comparison(const unsigned char *name, const unsigned char *pointer)
|
static cJSON_bool compare_pointers(const unsigned char *name, const unsigned char *pointer, const cJSON_bool case_sensitive)
|
||||||
{
|
{
|
||||||
if ((name == NULL) || (pointer == NULL))
|
if ((name == NULL) || (pointer == NULL))
|
||||||
{
|
{
|
||||||
@ -102,7 +102,7 @@ static cJSON_bool case_insensitive_pointer_comparison(const unsigned char *name,
|
|||||||
pointer++;
|
pointer++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (tolower(*name) != tolower(*pointer))
|
else if ((!case_sensitive && (tolower(*name) != tolower(*pointer))) || (case_sensitive && (*name != *pointer)))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
|
|||||||
{
|
{
|
||||||
current_element = current_element->child;
|
current_element = current_element->child;
|
||||||
/* GetObjectItem. */
|
/* GetObjectItem. */
|
||||||
while ((current_element != NULL) && !case_insensitive_pointer_comparison((unsigned char*)current_element->string, (const unsigned char*)pointer))
|
while ((current_element != NULL) && !compare_pointers((unsigned char*)current_element->string, (const unsigned char*)pointer, false))
|
||||||
{
|
{
|
||||||
current_element = current_element->next;
|
current_element = current_element->next;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user