MCPcopy Create free account
hub / github.com/DaveGamble/cJSON / compare_pointers

Function compare_pointers

cJSON_Utils.c:120–154  ·  view source on GitHub ↗

Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */

Source from the content-addressed store, hash-verified

118
119/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
120static cJSON_bool compare_pointers(const unsigned char *name, const unsigned char *pointer, const cJSON_bool case_sensitive)
121{
122 if ((name == NULL) || (pointer == NULL))
123 {
124 return false;
125 }
126
127 for (; (*name != '\0') && (*pointer != '\0') && (*pointer != '/'); (void)name++, pointer++) /* compare until next '/' */
128 {
129 if (*pointer == '~')
130 {
131 /* check for escaped '~' (~0) and '/' (~1) */
132 if (((pointer[1] != '0') || (*name != '~')) && ((pointer[1] != '1') || (*name != '/')))
133 {
134 /* invalid escape sequence or wrong character in *name */
135 return false;
136 }
137 else
138 {
139 pointer++;
140 }
141 }
142 else if ((!case_sensitive && (tolower(*name) != tolower(*pointer))) || (case_sensitive && (*name != *pointer)))
143 {
144 return false;
145 }
146 }
147 if (((*pointer != 0) && (*pointer != '/')) != (*name != 0))
148 {
149 /* one string has ended, the other not */
150 return false;;
151 }
152
153 return true;
154}
155
156/* calculate the length of a string if encoded as JSON pointer with ~0 and ~1 escape sequences */
157static size_t pointer_encoded_length(const unsigned char *string)

Callers 1

get_item_from_pointerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…