Skip to content

Commit 19ee8f2

Browse files
committed
new: ability to not build json_auto_parse and json_stringify functions
1 parent 75357a8 commit 19ee8f2

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ OPTION(JSON_HEX_NUMBERS "Enabled support of 0x integers" OFF)
1010
OPTION(JSON_PACKED "use packed json item structure" OFF)
1111
OPTION(JSON_SHORT_NEXT "use short type for next field of jsn_t" OFF)
1212

13+
OPTION(JSON_AUTO_PARSE_FN "Add json_auto_parse() function to the lib" ON)
14+
OPTION(JSON_STRINGIFY_FN "Add json_stringify() function to the lib" ON)
15+
1316

1417
OPTION(HOST_DEBUG "Log to console" OFF)
1518

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ A small footprint(code and memory) simple [JSON](https://www.rfc-editor.org/rfc/
2222
* `JSON_FLOATS`(OFF) -- Enable support of Floating point Numbers
2323
* `JSON_SHORT_NEXT`(OFF) -- Use `short` type for next field of jsn_t
2424
* `JSON_PACKED`(OFF) -- Use packed json item structure
25+
26+
* `JSON_AUTO_PARSE_FN'(ON) -- Build json_auto_parse() function
27+
* `JSON_STRINGIFY_FN'(ON) -- Build json_stringify() function
28+
2529
* `BUILD_TESTS`(ON) -- Build tests application
2630

2731
# Include files

nano/json.h.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#cmakedefine JSON_PACKED
99
#cmakedefine JSON_SHORT_NEXT
1010

11+
#cmakedefine JSON_AUTO_PARSE_FN
12+
#cmakedefine JSON_STRINGIFY_FN
13+
1114
#ifdef JSON_FLOATS
1215
#include "math.h"
1316
#endif
@@ -64,9 +67,13 @@ jsn_t;
6467

6568
int json_parse(jsn_t *pool, size_t size, /* <-- */ char *text);
6669

70+
#ifdef JSON_AUTO_PARSE_FN
6771
jsn_t *json_auto_parse(char *text, char **end);
72+
#endif
6873

74+
#ifdef JSON_STRINGIFY_FN
6975
char *json_stringify(char *outbuf, size_t size, /* <-- */ jsn_t *root);
76+
#endif
7077

7178

7279

@@ -108,7 +115,10 @@ jsn_t *json_cell(jsn_t *obj, int index);
108115
/* internal but may be usefull functions */
109116

110117
int string_unescape(char *s);
118+
119+
#ifdef JSON_STRINGIFY_FN
111120
char *string_escape(char *p, char *e, char const *s);
121+
#endif
112122

113123
int match_number(char **p, jsn_t *obj);
114124

parser.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ int json_parse(jsn_t *pool, size_t size, char *text)
374374
return basic_parse(&p);
375375
}
376376

377+
#ifdef JSON_AUTO_PARSE_FN
377378

378379
#define POOL_INCREASE_STEP (32)
379380

@@ -431,3 +432,4 @@ jsn_t *json_auto_parse(char *text, char **end)
431432
return p.pool;
432433
}
433434

435+
#endif /* JSON_AUTO_PARSE */

stringify.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "nano/json.h"
1010

11+
#ifdef JSON_STRINGIFY_FN
12+
1113
/* ------------------------------------------------------------------------ */
1214
char *string_escape(char *p, char *e, char const *s)
1315
{
@@ -102,3 +104,5 @@ char *json_stringify(char *out, size_t size, jsn_t *root)
102104
json_to_str(out, out + size - 1, root);
103105
return out;
104106
}
107+
108+
#endif /* JSON_STRINGIFY_FN */

0 commit comments

Comments
 (0)