Rename cJSONUtils_Pstrcasecmp to case_insensitive_pointer_comparison

Also changes the return type to cJSON_bool
This commit is contained in:
Max Bruckner 2017-04-30 14:19:52 +02:00
parent b73881a388
commit 6b01dee7ca

View File

@ -75,11 +75,11 @@ static int cJSONUtils_strcasecmp(const unsigned char *string1, const unsigned ch
}
/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
static int cJSONUtils_Pstrcasecmp(const unsigned char *name, const unsigned char *pointer)
static cJSON_bool case_insensitive_pointer_comparison(const unsigned char *name, const unsigned char *pointer)
{
if ((name == NULL) || (pointer == NULL))
{
return 1;
return false;
}
for (; (*name != '\0') && (*pointer != '\0') && (*pointer != '/'); (void)name++, pointer++) /* compare until next '/' */
@ -90,7 +90,7 @@ static int cJSONUtils_Pstrcasecmp(const unsigned char *name, const unsigned char
if (((pointer[1] != '0') || (*name != '~')) && ((pointer[1] != '1') || (*name != '/')))
{
/* invalid escape sequence or wrong character in *name */
return 1;
return false;
}
else
{
@ -99,16 +99,16 @@ static int cJSONUtils_Pstrcasecmp(const unsigned char *name, const unsigned char
}
else if (tolower(*name) != tolower(*pointer))
{
return 1;
return false;
}
}
if (((*pointer != 0) && (*pointer != '/')) != (*name != 0))
{
/* one string has ended, the other not */
return 1;
return false;;
}
return 0;
return true;
}
/* calculate the length of a string if encoded as JSON pointer with ~0 and ~1 escape sequences */
@ -270,7 +270,7 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
{
current_element = current_element->child;
/* GetObjectItem. */
while ((current_element != NULL) && cJSONUtils_Pstrcasecmp((unsigned char*)current_element->string, (const unsigned char*)pointer))
while ((current_element != NULL) && !case_insensitive_pointer_comparison((unsigned char*)current_element->string, (const unsigned char*)pointer))
{
current_element = current_element->next;
}