json: Move past the end char of a symbol

So that we can put a \0 there and continue parsing the rest of
the string. This allows us to in-place parse_string.
This commit is contained in:
Wim Taymans 2021-03-14 09:28:38 +01:00
parent 762663e74e
commit 2d1f84fd7d

View file

@ -112,7 +112,7 @@ static inline int spa_json_next(struct spa_json * iter, const char **value)
iter->state = __STRUCT; iter->state = __STRUCT;
if (iter->depth > 0) if (iter->depth > 0)
goto again; goto again;
return iter->cur - *value; return iter->cur++ - *value;
} }
continue; continue;
case __STRING: case __STRING:
@ -124,8 +124,7 @@ static inline int spa_json_next(struct spa_json * iter, const char **value)
iter->state = __STRUCT; iter->state = __STRUCT;
if (iter->depth > 0) if (iter->depth > 0)
continue; continue;
iter->cur++; return ++iter->cur - *value;
return iter->cur - *value;
case 240 ... 247: case 240 ... 247:
utf8_remain++; utf8_remain++;
SPA_FALLTHROUGH; SPA_FALLTHROUGH;
@ -308,6 +307,7 @@ static inline int spa_json_parse_string(const char *val, int len, char *result)
{ {
const char *p; const char *p;
if (!spa_json_is_string(val, len)) { if (!spa_json_is_string(val, len)) {
if (result != val)
strncpy(result, val, len); strncpy(result, val, len);
result += len; result += len;
} else { } else {