MCPcopy Create free account
hub / github.com/Netis/cloud-probe / compare_pointers

Function compare_pointers

cpworker/src/cJSON/cJSON_Utils.c:118–155  ·  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

116
117/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
118static cJSON_bool compare_pointers(const unsigned char *name, const unsigned char *pointer,
119 const cJSON_bool case_sensitive)
120{
121 if ((name == NULL) || (pointer == NULL))
122 {
123 return false;
124 }
125
126 for (; (*name != '\0') && (*pointer != '\0') && (*pointer != '/');
127 (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
154 return true;
155}
156
157/* calculate the length of a string if encoded as JSON pointer with ~0 and ~1 escape sequences */
158static 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