51 for (; *sb; sb = &(*sb)->
next)
52 if ((*sb)->idx ==
idx)
77 while (*p->
cp && strchr(
" \t\r\n", *p->
cp))
126 if (**p ==
'\\' && p[0][1])
148 if (p[0][1] > 0 && p[0][2] > 0 && p[0][3] > 0 && p[0][4] > 0)
153 size_t outbytesleft = 6;
155 sscanf(*p + 1,
"%4x%n", &code, &no_read);
170 else if (**p > 0 && **p <= 31)
190 p->
err_msg =
"string expected";
196 while (*cp && *cp !=
'"')
202 p->
err_msg =
"invalid character";
216 while (*cp && *cp !=
'"')
241 else if (*cp >=
'1' && *cp <=
'9')
244 while (*cp >=
'0' && *cp <=
'9')
255 if (*cp >=
'0' && *cp <=
'9')
257 while (*cp >=
'0' && *cp <=
'9')
266 if (*cp ==
'e' || *cp ==
'E')
269 if (*cp ==
'+' || *cp ==
'-')
271 if (*cp >=
'0' && *cp <=
'9')
273 while (*cp >=
'0' && *cp <=
'9')
282 v = strtod(p->
cp, &endptr);
305 else if (strchr(
"0123456789-", c))
317 while (c >=
'0' && c <=
'9')
335 while (c >=
'a' && c <=
'z' && i < 7)
342 if (!strcmp(tok,
"true"))
344 else if (!strcmp(tok,
"false"))
346 else if (!strcmp(tok,
"null"))
391 p->
err_msg =
"Too much nesting";
479 p->
err_msg =
"Too much nesting";
524 p->
err_msg =
"extra characters";
539 *errmsg =
"could not create parser";
561 if (l == 0 ||
wrbuf_buf(result)[l-1] ==
'\n')
564 for (i = 0; i < indent; i++)
573 sub_indent = indent + 2;
672 return &c->
u.
link[1];
732 np = &(*np)->
u.
link[1];
733 *np = src->
u.
link[0];
748 return p->
cp - p->
buf;
static int node(struct cql_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
Header for errno utilities.
void json_parser_destroy(json_parser_t p)
destroys JSON parser
const char * json_parser_get_errmsg(json_parser_t p)
returns parser error
static int json_one_char(const char **p, char *out)
static struct json_node * json_new_node(json_parser_t p, enum json_node_type type)
void json_parser_subst(json_parser_t p, int idx, struct json_node *n)
configure subst rule
static void json_indent(WRBUF result, int indent)
static int look_ch(json_parser_t p)
struct json_node * json_parser_parse(json_parser_t p, const char *json_str)
parses JSON string
static void move_ch(json_parser_t p)
static struct json_node * json_parse_elements(json_parser_t p)
void json_write_wrbuf(struct json_node *node, WRBUF result)
converts JSON tree to JSON string
void json_write_wrbuf_pretty(struct json_node *node, WRBUF result)
writes JSON tree with indentation (pretty print)
size_t json_parser_get_position(json_parser_t p)
returns parser position
static void json_write_wrbuf_r(struct json_node *node, WRBUF result, int indent)
struct json_node * json_parse(const char *json_str, const char **errmsg)
parses JSON string
struct json_node * json_parse2(const char *json_str, const char **errmsg, size_t *pos)
parses JSON string
int json_count_children(struct json_node *n)
returns number of children (array or object)
static struct json_node * json_parse_string(json_parser_t p)
static struct json_node * json_parse_number(json_parser_t p)
struct json_node * json_get_object(struct json_node *n, const char *name)
gets object pair value for some name
static struct json_node * json_parse_members(json_parser_t p)
struct json_node * json_get_elem(struct json_node *n, int idx)
gets array element
static struct json_node * json_parse_object(json_parser_t p)
void json_remove_node(struct json_node *n)
destroys JSON tree node and its children
static struct json_node * json_parse_value(json_parser_t p)
static struct json_node ** json_get_objectp(struct json_node *n, const char *name)
static struct json_node * json_parse_array(json_parser_t p)
struct json_node * json_detach_object(struct json_node *n, const char *name)
gets object value and detaches from existing tree
json_parser_t json_parser_create(void)
create JSON parser
static struct json_node * json_parse_pair(json_parser_t p)
int json_append_array(struct json_node *dst, struct json_node *src)
appends array to another
Header for JSON functions.
struct json_parser_s * json_parser_t
JSON parser (opaque)
json_node_type
JSON node type for json_node.
struct json_node * link[2]
struct json_subst_info * subst
struct json_subst_info * next
size_t yaz_write_UTF8_char(unsigned long x, char **outbuf, size_t *outbytesleft, int *error)
encodes UTF-8 sequence
void wrbuf_json_puts(WRBUF b, const char *str)
writes JSON text to WRBUF with escaping
void wrbuf_printf(WRBUF b, const char *fmt,...)
writes printf result to WRBUF
void wrbuf_puts(WRBUF b, const char *buf)
appends C-string to WRBUF
Header for memory handling functions.
#define xfree(x)
utility macro which calls xfree_f
#define xmalloc(x)
utility macro which calls malloc_f