Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
| 118 | |
| 119 | /* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */ |
| 120 | static 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 */ |
| 157 | static size_t pointer_encoded_length(const unsigned char *string) |
no outgoing calls
no test coverage detected
searching dependent graphs…