mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
reformatting: cJSON_Minify
This commit is contained in:
parent
9adc6e7fe1
commit
34388c2d4c
73
cJSON.c
73
cJSON.c
@ -2127,17 +2127,64 @@ cJSON *cJSON_Duplicate(cJSON *item, int recurse)
|
|||||||
|
|
||||||
void cJSON_Minify(char *json)
|
void cJSON_Minify(char *json)
|
||||||
{
|
{
|
||||||
char *into=json;
|
char *into = json;
|
||||||
while (*json)
|
while (*json)
|
||||||
{
|
{
|
||||||
if (*json==' ') json++;
|
if (*json == ' ')
|
||||||
else if (*json=='\t') json++; /* Whitespace characters. */
|
{
|
||||||
else if (*json=='\r') json++;
|
json++;
|
||||||
else if (*json=='\n') json++;
|
}
|
||||||
else if (*json=='/' && json[1]=='/') while (*json && *json!='\n') json++; /* double-slash comments, to end of line. */
|
else if (*json == '\t')
|
||||||
else if (*json=='/' && json[1]=='*') {while (*json && !(*json=='*' && json[1]=='/')) json++;json+=2;} /* multiline comments. */
|
{
|
||||||
else if (*json=='\"'){*into++=*json++;while (*json && *json!='\"'){if (*json=='\\') *into++=*json++;*into++=*json++;}*into++=*json++;} /* string literals, which are \" sensitive. */
|
/* Whitespace characters. */
|
||||||
else *into++=*json++; /* All other characters. */
|
json++;
|
||||||
}
|
}
|
||||||
*into=0; /* and null-terminate. */
|
else if (*json == '\r')
|
||||||
|
{
|
||||||
|
json++;
|
||||||
|
}
|
||||||
|
else if (*json=='\n')
|
||||||
|
{
|
||||||
|
json++;
|
||||||
|
}
|
||||||
|
else if ((*json == '/') && (json[1] == '/'))
|
||||||
|
{
|
||||||
|
/* double-slash comments, to end of line. */
|
||||||
|
while (*json && (*json != '\n'))
|
||||||
|
{
|
||||||
|
json++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((*json == '/') && (json[1] == '*'))
|
||||||
|
{
|
||||||
|
/* multiline comments. */
|
||||||
|
while (*json && !((*json == '*') && (json[1] == '/')))
|
||||||
|
{
|
||||||
|
json++;
|
||||||
|
}
|
||||||
|
json += 2;
|
||||||
|
}
|
||||||
|
else if (*json == '\"')
|
||||||
|
{
|
||||||
|
/* string literals, which are \" sensitive. */
|
||||||
|
*into++ = *json++;
|
||||||
|
while (*json && (*json != '\"'))
|
||||||
|
{
|
||||||
|
if (*json == '\\')
|
||||||
|
{
|
||||||
|
*into++=*json++;
|
||||||
|
}
|
||||||
|
*into++ = *json++;
|
||||||
|
}
|
||||||
|
*into++ = *json++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* All other characters. */
|
||||||
|
*into++ = *json++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* and null-terminate. */
|
||||||
|
*into = '\0';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user