mirror of
https://github.com/DaveGamble/cJSON
synced 2025-04-01 22:49:12 +00:00
refactor cJSONUtils_InplaceDecodePointerString
This commit is contained in:
parent
378a333ee2
commit
4ba6bafe34
@ -288,22 +288,35 @@ CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *po
|
|||||||
/* JSON Patch implementation. */
|
/* JSON Patch implementation. */
|
||||||
static void cJSONUtils_InplaceDecodePointerString(unsigned char *string)
|
static void cJSONUtils_InplaceDecodePointerString(unsigned char *string)
|
||||||
{
|
{
|
||||||
unsigned char *s2 = string;
|
unsigned char *decoded_string = string;
|
||||||
|
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; *string; (void)s2++, string++)
|
for (; *string; (void)decoded_string++, string++)
|
||||||
{
|
{
|
||||||
*s2 = (unsigned char) ((*string != '~')
|
if (string[0] == '~')
|
||||||
? (*string)
|
{
|
||||||
: ((*(++string) == '0')
|
if (string[1] == '0')
|
||||||
? '~'
|
{
|
||||||
: '/'));
|
decoded_string[0] = '~';
|
||||||
|
}
|
||||||
|
else if (string[1] == '1')
|
||||||
|
{
|
||||||
|
decoded_string[1] = '/';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* invalid escape sequence */
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
*s2 = '\0';
|
string++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
decoded_string[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* non-broken cJSON_DetachItemFromArray */
|
/* non-broken cJSON_DetachItemFromArray */
|
||||||
|
Loading…
Reference in New Issue
Block a user