libscipaper 1.0.x
nxjson.h
1/*
2 * Copyright (c) 2013 Yaroslav Stavnichiy <yarosla@gmail.com>
3 *
4 * This file is part of NXJSON.
5 *
6 * NXJSON is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation, either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * NXJSON is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with NXJSON. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NXJSON_H
21#define NXJSON_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
44
48typedef struct nx_json {
50 const char* key;
51 const char* text_value;
52 long long int_value;
53 double dbl_value;
54 int length;
55 struct nx_json* child;
56 struct nx_json* next;
57 struct nx_json* last_child;
58} nx_json;
59
64typedef int (*nx_json_unicode_encoder)(unsigned int codepoint, char* p, char** endp);
65
66extern nx_json_unicode_encoder nx_json_unicode_to_utf8;
67
74const nx_json* nx_json_parse(char* text, nx_json_unicode_encoder encoder);
75
81const nx_json* nx_json_parse_utf8(char* text);
82
86void nx_json_free(const nx_json* js);
87
96const nx_json* nx_json_get(const nx_json* json, const char* key);
97
106const nx_json* nx_json_item(const nx_json* json, int idx);
107
110#ifdef __cplusplus
111}
112#endif
113
114#endif /* NXJSON_H */
const nx_json * nx_json_item(const nx_json *json, int idx)
Gets an array element by index This function never returns NULL or fails for any reason.
void nx_json_free(const nx_json *js)
Frees a nx_json struct parsed by nx_json_parse()
nx_json_type
This enum is used in nx_json to discribe what type a given json entry has.
Definition nxjson.h:35
const nx_json * nx_json_get(const nx_json *json, const char *key)
Gets object's property or child by key.
const nx_json * nx_json_parse_utf8(char *text)
This is shortcut for nx_json_parse(text, nx_json_unicode_to_utf8) where nx_json_unicode_to_utf8 is un...
const nx_json * nx_json_parse(char *text, nx_json_unicode_encoder encoder)
This struct discribes a parsed entry or file.
int(* nx_json_unicode_encoder)(unsigned int codepoint, char *p, char **endp)
this typdef descibes a function that takes a Unicode codepoint and writes corresponding encoded value...
Definition nxjson.h:64
@ NX_JSON_NULL
this is null value
Definition nxjson.h:36
@ NX_JSON_STRING
this is a string; value can be found in text_value field
Definition nxjson.h:39
@ NX_JSON_OBJECT
this is an object; properties can be found in child nodes
Definition nxjson.h:37
@ NX_JSON_DOUBLE
this is a double; value can be found in dbl_value field
Definition nxjson.h:41
@ NX_JSON_INTEGER
this is an integer; value can be found in int_value field
Definition nxjson.h:40
@ NX_JSON_ARRAY
this is an array; items can be found in child nodes
Definition nxjson.h:38
@ NX_JSON_BOOL
this is a boolean; value can be found in int_value field
Definition nxjson.h:42
This struct discribes a parsed entry or file.
Definition nxjson.h:48
int length
number of children of OBJECT or ARRAY
Definition nxjson.h:54
const char * text_value
text value of STRING node
Definition nxjson.h:51
nx_json_type type
type of json node, see above
Definition nxjson.h:49
long long int_value
the value of INTEGER or BOOL node
Definition nxjson.h:52
struct nx_json * next
points to next child
Definition nxjson.h:56
struct nx_json * child
points to first child
Definition nxjson.h:55
const char * key
key of the property; for object's children only
Definition nxjson.h:50
double dbl_value
the value of DOUBLE node
Definition nxjson.h:53