Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ int main(void) {
- `-D MJSON_ENABLE_MERGE=0` disable `mjson_merge()`, default: enabled
- `-D MJSON_ENABLE_NEXT=0` disable `mjson_next()`, default: enabled
- `-D MJSON_REALLOC=my_realloc` redefine realloc() used by `mjson_print_dynamic_buf()`, default: realloc
- `-D MJSON_DEBUG=true` enable `PLEN2` debug mode


# Parsing API
Expand Down
28 changes: 24 additions & 4 deletions src/mjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,31 @@ static int plen1(const char *s) {
return n;
}

/*
* This function calculates the position of the `.`
* when the json key have a `.` in the key name
*
* Input: the json key
* Output: the position after the `.`
*/
static int plen2(const char *s) {
int i = 0, n = 0;
while (s[i] != '\0' && s[i] != '.' && s[i] != '[')
n++, i += s[i] == '\\' ? 2 : 1;
// printf("PLEN: s: [%s], [%.*s] => %d\n", s, i, s, n);
int i = 0;

#if MJSON_DEBUG
int n = 0;
#endif

while (s[i] != '\0' && s[i] != '.' && s[i] != '['){
i += s[i] == '\\' ? 2 : 1;
#if MJSON_DEBUG
n++;
#endif
}

#if MJSON_DEBUG
printf("PLEN2: s: [%s], [%.*s] => %d\n", s, i, s, n);
#endif

return i;
}

Expand Down