-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonw.h
More file actions
51 lines (46 loc) · 2.3 KB
/
jsonw.h
File metadata and controls
51 lines (46 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdbool.h>
#include <stddef.h>
typedef enum {
JSONW_NULL,
JSONW_BOOLEAN,
JSONW_NUMBER,
JSONW_STRING,
JSONW_ARRAY,
JSONW_OBJECT,
} jsonw_ty;
// basic parsers
char *jsonw_litchr(char chr, char *json); // literal character `chr`
char *jsonw_litstr(char *str, char *json); // literal string `str`
// characters
char *jsonw_ws(char *json); // /[ \t\n\r]*/
char *jsonw_beginarr(char *json); // ws '[' ws
char *jsonw_endarr(char *json); // ws ']' ws
char *jsonw_beginobj(char *json); // ws '{' ws
char *jsonw_endobj(char *json); // ws '}' ws
char *jsonw_namesep(char *json); // ws ':' ws
char *jsonw_valuesep(char *json); // ws ',' ws
char *jsonw_beginstr(char *json); // '"'
char *jsonw_endstr(char *json); // '"'
// values, texts
char *jsonw_null(char *json); // 'null'
char *jsonw_boolean(bool *b, char *json); // 'true' | 'false'
char *jsonw_number(double *num, char *json); // e.g. '64', '-1.5e+10'
char *jsonw_character(char *chr, char *json); // e.g. 'c', '\n', '\u007c'
char *jsonw_string(size_t *len, char *json); // e.g. '"abc"', '"\tdef\n"'
char *jsonw_name(char *json); // e.g. '"abc":'
char *jsonw_element(char *json); // e.g. '"def",', '123,'
char *jsonw_member(char *json); // e.g. '"abc": 123,'
char *jsonw_array(size_t *len, char *json); // e.g. '[ "def", 123 }'
char *jsonw_object(size_t *len, char *json); // e.g. '{ "abc": 123 }'
char *jsonw_primitive(jsonw_ty *type, char *json); // null | bool | num | str
char *jsonw_structured(jsonw_ty *type, char *json); // object | array
char *jsonw_value(jsonw_ty *type, char *json); // primitive | structured
char *jsonw_text(jsonw_ty *type, char *json); // ws value ws
// utilities
int jsonw_strcmp(char *str, char *json); // compare C string to JSON string lit
char *jsonw_index(size_t idx, char *json); // get subscript `idx` of array
char *jsonw_find(char *name, char *json); // find key `name` in object
char *jsonw_lookup(char *name, char *json); // look up value of key `name`
char *jsonw_quote(char buf[sizeof("\\u0000")], char chr); // escape char lit
char *jsonw_escape(char *buf, size_t size, char *str); // escape string lit
char *jsonw_unescape(char *buf, size_t size, char *json); // unecsape string lit