mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
reformatting: cJSON_ParseWithOpts
This commit is contained in:
parent
f1dd51bfb5
commit
e809022349
46
cJSON.c
46
cJSON.c
@ -785,21 +785,45 @@ static const char *skip(const char *in)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Parse an object - create a new root, and populate. */
|
/* Parse an object - create a new root, and populate. */
|
||||||
cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated)
|
cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int require_null_terminated)
|
||||||
{
|
{
|
||||||
const char *end=0,**ep=return_parse_end?return_parse_end:&global_ep;
|
const char *end = 0;
|
||||||
cJSON *c=cJSON_New_Item();
|
/* use global error pointer if no specific one was given */
|
||||||
*ep=0;
|
const char **ep = return_parse_end ? return_parse_end : &global_ep;
|
||||||
if (!c) return 0; /* memory fail */
|
cJSON *c = cJSON_New_Item();
|
||||||
|
*ep = 0;
|
||||||
|
if (!c) /* memory fail */
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
end=parse_value(c,skip(value),ep);
|
end = parse_value(c, skip(value), ep);
|
||||||
if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */
|
if (!end)
|
||||||
|
{
|
||||||
|
/* parse failure. ep is set. */
|
||||||
|
cJSON_Delete(c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
|
/* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
|
||||||
if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);*ep=end;return 0;}}
|
if (require_null_terminated)
|
||||||
if (return_parse_end) *return_parse_end=end;
|
{
|
||||||
return c;
|
end = skip(end);
|
||||||
|
if (*end)
|
||||||
|
{
|
||||||
|
cJSON_Delete(c);
|
||||||
|
*ep = end;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (return_parse_end)
|
||||||
|
{
|
||||||
|
*return_parse_end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Default options for cJSON_Parse */
|
/* Default options for cJSON_Parse */
|
||||||
cJSON *cJSON_Parse(const char *value) {return cJSON_ParseWithOpts(value,0,0);}
|
cJSON *cJSON_Parse(const char *value) {return cJSON_ParseWithOpts(value,0,0);}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user