Skip to content

Commit

Permalink
Add support for inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Mar 28, 2021
1 parent 3281ace commit 202c16b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lwjson/src/include/lwjson/lwjson_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ extern "C" {
#define LWJSON_CFG_INT_TYPE long long
#endif

/**
* \brief Enables `1` or disables `0` support for inline comments
*
* Default set to `0` to be JSON compliant
*/
#ifndef LWJSON_CFG_COMMENTS
#define LWJSON_CFG_COMMENTS 0
#endif

/**
* \}
*/
Expand Down
23 changes: 21 additions & 2 deletions lwjson/src/lwjson/lwjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,28 @@ prv_skip_blank(const char** p) {
while (s != NULL && *s != '\0') {
if (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n' || *s == '\f') {
++s;
continue;
#if LWJSON_CFG_COMMENTS
/* Check for comments and remove them */
} else if (*s == '/') {
const char* cs = s;
++cs;
if (cs != NULL && *cs == '*') {
++cs;
while (cs != NULL && *cs != '\0') {
if (*cs == '*') {
++cs;
if (*cs == '/') {
s = ++cs;
break;
}
}
++cs;
}
}
#endif /* LWJSON_CFG_COMMENTS */
} else {
break;
}
break;
}
*p = s;
if (s != NULL && *s != '\0') {
Expand Down

0 comments on commit 202c16b

Please sign in to comment.