src/cx/json.h

Sun, 12 Jan 2025 13:04:32 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 12 Jan 2025 13:04:32 +0100
changeset 1123
2b83302d595a
parent 1117
54df904472b0
permissions
-rw-r--r--

make escaping slashes optional - fixes #569

937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved.
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
29 * @file json.h
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
30 * @brief Interface for parsing data from JSON files.
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
31 * @author Mike Becker
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
32 * @author Olaf Wintermann
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
33 * @copyright 2-Clause BSD License
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 */
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 #ifndef UCX_JSON_H
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 #define UCX_JSON_H
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 #include "common.h"
996
333155f234c4 add support for allocators to the json parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 988
diff changeset
40 #include "allocator.h"
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 #include "string.h"
1007
81b2986d2b04 fix that cxBufferSeek() cannot move pos past the end - fixes #523
Mike Becker <universe@uap-core.de>
parents: 1002
diff changeset
42 #include "buffer.h"
967
a58f602ed2fe simplify parsing of array and object elements
Mike Becker <universe@uap-core.de>
parents: 966
diff changeset
43 #include "array_list.h"
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44
1042
c17f11830a2d add missing libc string.h include
Mike Becker <universe@uap-core.de>
parents: 1037
diff changeset
45 #include <string.h>
c17f11830a2d add missing libc string.h include
Mike Becker <universe@uap-core.de>
parents: 1037
diff changeset
46
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 #ifdef __cplusplus
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 extern "C" {
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 #endif
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
51
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
52 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
53 * The type of the parsed token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
54 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 enum cx_json_token_type {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
56 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
57 * No complete token parsed, yet.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
58 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 CX_JSON_NO_TOKEN,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
60 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
61 * The presumed token contains syntactical errors.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
62 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 CX_JSON_TOKEN_ERROR,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
64 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
65 * A "begin of array" '[' token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
66 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 CX_JSON_TOKEN_BEGIN_ARRAY,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
68 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
69 * A "begin of object" '{' token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
70 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 CX_JSON_TOKEN_BEGIN_OBJECT,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
72 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
73 * An "end of array" ']' token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
74 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 CX_JSON_TOKEN_END_ARRAY,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
76 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
77 * An "end of object" '}' token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
78 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 CX_JSON_TOKEN_END_OBJECT,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
80 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
81 * A colon ':' token separating names and values.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
82 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 CX_JSON_TOKEN_NAME_SEPARATOR,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
84 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
85 * A comma ',' token separating object entries or array elements.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
86 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 CX_JSON_TOKEN_VALUE_SEPARATOR,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
88 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
89 * A string token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
90 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 CX_JSON_TOKEN_STRING,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
92 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
93 * A number token that can be represented as integer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
94 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 CX_JSON_TOKEN_INTEGER,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
96 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
97 * A number token that cannot be represented as integer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
98 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 CX_JSON_TOKEN_NUMBER,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
100 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
101 * A literal token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
102 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 CX_JSON_TOKEN_LITERAL,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
104 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
105 * A white-space token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
106 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 CX_JSON_TOKEN_SPACE
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
110 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
111 * The type of some JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
112 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 enum cx_json_value_type {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
114 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
115 * Reserved.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
116 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 CX_JSON_NOTHING, // this allows us to always return non-NULL values
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
118 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
119 * A JSON object.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
120 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 CX_JSON_OBJECT,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
122 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
123 * A JSON array.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
124 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 CX_JSON_ARRAY,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
126 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
127 * A string.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
128 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 CX_JSON_STRING,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
130 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
131 * A number that contains an integer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
132 */
966
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
133 CX_JSON_INTEGER,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
134 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
135 * A number, not necessarily an integer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
136 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 CX_JSON_NUMBER,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
138 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
139 * A literal (true, false, null).
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
140 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 CX_JSON_LITERAL
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
144 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
145 * JSON literal types.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
146 */
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
147 enum cx_json_literal {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
148 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
149 * The @c null literal.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
150 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 CX_JSON_NULL,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
152 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
153 * The @c true literal.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
154 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 CX_JSON_TRUE,
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
156 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
157 * The @c false literal.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
158 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 CX_JSON_FALSE
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
162 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
163 * Type alias for the token type enum.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
164 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 typedef enum cx_json_token_type CxJsonTokenType;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
166 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
167 * Type alias for the value type enum.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
168 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 typedef enum cx_json_value_type CxJsonValueType;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
171 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
172 * Type alias for the JSON parser interface.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
173 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 typedef struct cx_json_s CxJson;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
175
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
176 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
177 * Type alias for the token struct.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
178 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 typedef struct cx_json_token_s CxJsonToken;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
181 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
182 * Type alias for the JSON value struct.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
183 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 typedef struct cx_json_value_s CxJsonValue;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
186 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
187 * Type alias for the JSON array struct.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
188 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 typedef struct cx_json_array_s CxJsonArray;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
190 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
191 * Type alias for the JSON object struct.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
192 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 typedef struct cx_json_object_s CxJsonObject;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
194 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
195 * Type alias for a JSON string.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
196 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 typedef struct cx_mutstr_s CxJsonString;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
198 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
199 * Type alias for a number that can be represented as 64-bit signed integer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
200 */
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
201 typedef int64_t CxJsonInteger;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
202 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
203 * Type alias for number that is not an integer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
204 */
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
205 typedef double CxJsonNumber;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
206 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
207 * Type alias for a JSON literal.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
208 */
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
209 typedef enum cx_json_literal CxJsonLiteral;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
211 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
212 * Type alias for a key/value pair in a JSON object.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
213 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214 typedef struct cx_json_obj_value_s CxJsonObjValue;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
216 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
217 * JSON array structure.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
218 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 struct cx_json_array_s {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
220 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
221 * The array data.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
222 */
967
a58f602ed2fe simplify parsing of array and object elements
Mike Becker <universe@uap-core.de>
parents: 966
diff changeset
223 CX_ARRAY_DECLARE(CxJsonValue*, array);
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
226 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
227 * JSON object structure.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
228 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 struct cx_json_object_s {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
230 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
231 * The key/value entries.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
232 */
967
a58f602ed2fe simplify parsing of array and object elements
Mike Becker <universe@uap-core.de>
parents: 966
diff changeset
233 CX_ARRAY_DECLARE(CxJsonObjValue, values);
1082
46cdc8689fc4 implement index array to preserve order of json object members
Mike Becker <universe@uap-core.de>
parents: 1079
diff changeset
234 /**
46cdc8689fc4 implement index array to preserve order of json object members
Mike Becker <universe@uap-core.de>
parents: 1079
diff changeset
235 * The original indices to reconstruct the order in which the members were added.
46cdc8689fc4 implement index array to preserve order of json object members
Mike Becker <universe@uap-core.de>
parents: 1079
diff changeset
236 */
46cdc8689fc4 implement index array to preserve order of json object members
Mike Becker <universe@uap-core.de>
parents: 1079
diff changeset
237 size_t *indices;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
240 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
241 * Structure for a key/value entry in a JSON object.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
242 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 struct cx_json_obj_value_s {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
244 /**
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
245 * The key (or name in JSON terminology) of the value.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
246 */
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
247 cxmutstr name;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
248 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
249 * The value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
250 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 CxJsonValue *value;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
254 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
255 * Structure for a JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
256 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 struct cx_json_value_s {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
258 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
259 * The allocator with which the value was allocated.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
260 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
261 * Required for recursively deallocating memory of objects and arrays.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
262 */
996
333155f234c4 add support for allocators to the json parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 988
diff changeset
263 const CxAllocator *allocator;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
264 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
265 * The type of this value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
266 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
267 * Specifies how the @c value union shall be resolved.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
268 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 CxJsonValueType type;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
270 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
271 * The value data.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
272 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 union {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
274 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
275 * The array data if type is #CX_JSON_ARRAY.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
276 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 CxJsonArray array;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
278 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
279 * The object data if type is #CX_JSON_OBJECT.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
280 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 CxJsonObject object;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
282 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
283 * The string data if type is #CX_JSON_STRING.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
284 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 CxJsonString string;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
286 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
287 * The integer if type is #CX_JSON_INTEGER.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
288 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 CxJsonInteger integer;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
290 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
291 * The number if type is #CX_JSON_NUMBER.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
292 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 CxJsonNumber number;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
294 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
295 * The literal type if type is #CX_JSON_LITERAL.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
296 */
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 CxJsonLiteral literal;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 } value;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 };
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
301 /**
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
302 * Internally used structure for a parsed token.
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
303 *
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
304 * You should never need to use this in your code.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
305 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
306 struct cx_json_token_s {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
307 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
308 * The token type.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
309 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
310 CxJsonTokenType tokentype;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
311 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
312 * True, iff the @c content must be passed to cx_strfree().
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
313 */
1002
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
314 bool allocated;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
315 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
316 * The token text, if any.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
317 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
318 * This is not necessarily set when the token type already
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
319 * uniquely identifies the content.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
320 */
1002
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
321 cxmutstr content;
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
322 };
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
324 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
325 * The JSON parser interface.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
326 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
327 struct cx_json_s {
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
328 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
329 * The allocator used for produced JSON values.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
330 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
331 const CxAllocator *allocator;
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
332 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
333 * The input buffer.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
334 */
1007
81b2986d2b04 fix that cxBufferSeek() cannot move pos past the end - fixes #523
Mike Becker <universe@uap-core.de>
parents: 1002
diff changeset
335 CxBuffer buffer;
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
336
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
337 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
338 * Used internally.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
339 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
340 * Remembers the prefix of the last uncompleted token.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
341 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
342 CxJsonToken uncompleted;
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
343
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
344 /**
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
345 * A pointer to an intermediate state of the currently parsed value.
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
346 *
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
347 * Never access this value manually.
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
348 */
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
349 CxJsonValue *parsed;
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
350
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
351 /**
1067
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
352 * A pointer to an intermediate state of a currently parsed object member.
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
353 *
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
354 * Never access this value manually.
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
355 */
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
356 CxJsonObjValue uncompleted_member;
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
357
7799addf475f optimize cxJsonObjGet() part 1 - binary search
Mike Becker <universe@uap-core.de>
parents: 1060
diff changeset
358 /**
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
359 * State stack.
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
360 */
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
361 CX_ARRAY_DECLARE_SIZED(int, states, unsigned);
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
362
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
363 /**
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
364 * Value buffer stack.
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
365 */
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
366 CX_ARRAY_DECLARE_SIZED(CxJsonValue*, vbuf, unsigned);
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
367
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
368 /**
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
369 * Internally reserved memory for the state stack.
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
370 */
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
371 int states_internal[8];
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
372
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
373 /**
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
374 * Internally reserved memory for the value buffer stack.
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
375 */
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
376 CxJsonValue* vbuf_internal[8];
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
377
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
378 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
379 * Used internally.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
380 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
381 bool tokenizer_escape; // TODO: check if it can be replaced with look-behind
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
382 };
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
383
1002
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
384 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
385 * Status codes for the json interface.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
386 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
387 enum cx_json_status {
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
388 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
389 * Everything is fine.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
390 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
391 CX_JSON_NO_ERROR,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
392 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
393 * The input buffer does not contain more data.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
394 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
395 CX_JSON_NO_DATA,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
396 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
397 * The input ends unexpectedly.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
398 *
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
399 * Refill the buffer with cxJsonFill() to complete the json data.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
400 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
401 CX_JSON_INCOMPLETE_DATA,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
402 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
403 * Not used as a status and never returned by any function.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
404 *
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
405 * You can use this enumerator to check for all "good" status results
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
406 * by checking if the status is less than @c CX_JSON_OK.
1002
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
407 *
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
408 * A "good" status means, that you can refill data and continue parsing.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
409 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
410 CX_JSON_OK,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
411 /**
1060
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
412 * The input buffer has never been filled.
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
413 */
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
414 CX_JSON_NULL_DATA,
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
415 /**
1002
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
416 * Allocating memory for the internal buffer failed.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
417 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
418 CX_JSON_BUFFER_ALLOC_FAILED,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
419 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
420 * Allocating memory for a json value failed.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
421 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
422 CX_JSON_VALUE_ALLOC_FAILED,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
423 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
424 * A number value is incorrectly formatted.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
425 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
426 CX_JSON_FORMAT_ERROR_NUMBER,
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
427 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
428 * The tokenizer found something unexpected.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
429 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
430 CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
431 };
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
432
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
433 /**
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
434 * Typedef for the json status enum.
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
435 */
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
436 typedef enum cx_json_status CxJsonStatus;
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
437
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
438 /**
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
439 * The JSON writer settings.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
440 */
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
441 struct cx_json_writer_s {
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
442 /**
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
443 * Set true to enable pretty output.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
444 */
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
445 bool pretty;
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
446 /**
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
447 * Set false to output the members in the order in which they were added.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
448 */
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
449 bool sort_members;
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
450 /**
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
451 * The maximum number of fractional digits in a number value.
1117
54df904472b0 add fractional number formatting - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1097
diff changeset
452 * The default value is 6 and values larger than 15 are reduced to 15.
54df904472b0 add fractional number formatting - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1097
diff changeset
453 * Note, that the actual number of digits may be lower, depending on the concrete number.
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
454 */
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
455 uint8_t frac_max_digits;
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
456 /**
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
457 * Set true to use spaces instead of tab characters.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
458 * Indentation is only used in pretty output.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
459 */
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
460 bool indent_space;
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
461 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
462 * If @c indent_space is true, this is the number of spaces per tab.
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
463 * Indentation is only used in pretty output.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
464 */
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
465 uint8_t indent;
1123
2b83302d595a make escaping slashes optional - fixes #569
Mike Becker <universe@uap-core.de>
parents: 1117
diff changeset
466 /**
2b83302d595a make escaping slashes optional - fixes #569
Mike Becker <universe@uap-core.de>
parents: 1117
diff changeset
467 * Set true to enable escaping of the slash character (solidus).
2b83302d595a make escaping slashes optional - fixes #569
Mike Becker <universe@uap-core.de>
parents: 1117
diff changeset
468 */
2b83302d595a make escaping slashes optional - fixes #569
Mike Becker <universe@uap-core.de>
parents: 1117
diff changeset
469 bool escape_slash;
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
470 };
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
471
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
472 /**
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
473 * Typedef for the json writer.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
474 */
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
475 typedef struct cx_json_writer_s CxJsonWriter;
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
476
1077
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
477 /**
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
478 * Creates a default writer configuration for compact output.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
479 *
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
480 * @return new JSON writer settings
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
481 */
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
482 cx_attr_nodiscard
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
483 CxJsonWriter cxJsonWriterCompact(void);
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
484
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
485 /**
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
486 * Creates a default writer configuration for pretty output.
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
487 *
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
488 * @param use_spaces false if you want tabs, true if you want four spaces instead
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
489 * @return new JSON writer settings
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
490 */
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
491 cx_attr_nodiscard
911a154dd469 add functions to create default JSON writers - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1072
diff changeset
492 CxJsonWriter cxJsonWriterPretty(bool use_spaces);
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
493
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
494 /**
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
495 * Writes a JSON value to a buffer or stream.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
496 *
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
497 * This function blocks until all data is written or an error when trying
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
498 * to write data occurs.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
499 * The write operation is not atomic in the sense that it might happen
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
500 * that the data is only partially written when an error occurs with no
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
501 * way to indicate how much data was written.
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
502 * To avoid this problem, you can use a CxBuffer as @p target which is
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
503 * unlikely to fail a write operation and either use the buffer's flush
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
504 * feature to relay the data or use the data in the buffer manually to
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
505 * write it to the actual target.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
506 *
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
507 * @param target the buffer or stream where to write to
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
508 * @param value the value that shall be written
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
509 * @param wfunc the write function to use
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
510 * @param settings formatting settings (or @c NULL to use a compact default)
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
511 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
512 * @retval non-zero when no or not all data could be written
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
513 */
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
514 cx_attr_nonnull_arg(1, 2, 3)
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
515 int cxJsonWrite(
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
516 void* target,
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
517 const CxJsonValue* value,
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
518 cx_write_func wfunc,
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
519 const CxJsonWriter* settings
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
520 );
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
521
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
522 /**
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
523 * Initializes the json interface.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
524 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
525 * @param json the json interface
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
526 * @param allocator the allocator that shall be used for the produced values
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
527 * @see cxJsonDestroy()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
528 */
1000
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
529 cx_attr_nonnull_arg(1)
1aecddf7e209 simplify how the json parser works
Mike Becker <universe@uap-core.de>
parents: 996
diff changeset
530 void cxJsonInit(CxJson *json, const CxAllocator *allocator);
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
531
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
532 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
533 * Destroys the json interface.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
534 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
535 * @param json the json interface
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
536 * @see cxJsonInit()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
537 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
538 cx_attr_nonnull
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
539 void cxJsonDestroy(CxJson *json);
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
540
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
541 /**
1013
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
542 * Destroys and re-initializes the json interface.
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
543 *
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
544 * You might want to use this, to reset the parser after
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
545 * encountering a syntax error.
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
546 *
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
547 * @param json the json interface
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
548 */
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
549 cx_attr_nonnull
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
550 static inline void cxJsonReset(CxJson *json) {
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
551 const CxAllocator *allocator = json->allocator;
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
552 cxJsonDestroy(json);
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
553 cxJsonInit(json, allocator);
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
554 }
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
555
add8358fc3c3 add cxJsonReset() and cxPropertiesReset()
Mike Becker <universe@uap-core.de>
parents: 1012
diff changeset
556 /**
1060
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
557 * Fills the input buffer.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
558 *
1060
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
559 * @remark The JSON interface tries to avoid copying the input data.
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
560 * When you use this function and cxJsonNext() interleaving,
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
561 * no copies are performed. However, you must not free the
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
562 * pointer to the data in that case. When you invoke the fill
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
563 * function more than once before calling cxJsonNext(),
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
564 * the additional data is appended - inevitably leading to
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
565 * an allocation of a new buffer and copying the previous contents.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
566 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
567 * @param json the json interface
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
568 * @param buf the source buffer
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
569 * @param len the length of the source buffer
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
570 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
571 * @retval non-zero internal allocation error
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
572 * @see cxJsonFill()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
573 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
574 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
575 cx_attr_access_r(2, 3)
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
576 int cxJsonFilln(CxJson *json, const char *buf, size_t len);
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
577
988
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
578 #ifdef __cplusplus
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
579 } // extern "C"
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
580
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
581 cx_attr_nonnull
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
582 static inline int cxJsonFill(
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
583 CxJson *json,
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
584 cxstring str
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
585 ) {
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
586 return cxJsonFilln(json, str.ptr, str.length);
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
587 }
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
588
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
589 cx_attr_nonnull
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
590 static inline int cxJsonFill(
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
591 CxJson *json,
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
592 cxmutstr str
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
593 ) {
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
594 return cxJsonFilln(json, str.ptr, str.length);
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
595 }
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
596
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
597 cx_attr_nonnull
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
598 cx_attr_cstr_arg(2)
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
599 static inline int cxJsonFill(
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
600 CxJson *json,
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
601 const char *str
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
602 ) {
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
603 return cxJsonFilln(json, str, strlen(str));
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
604 }
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
605
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
606 extern "C" {
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
607 #else // __cplusplus
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
608 /**
1060
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
609 * Fills the input buffer.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
610 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
611 * The JSON interface tries to avoid copying the input data.
1060
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
612 * When you use this function and cxJsonNext() interleaving,
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
613 * no copies are performed. However, you must not free the
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
614 * pointer to the data in that case. When you invoke the fill
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
615 * function more than once before calling cxJsonNext(),
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
616 * the additional data is appended - inevitably leading to
0a7c1bb2372d avoid copying the filled data in the json parser when possible - fixes #530
Mike Becker <universe@uap-core.de>
parents: 1056
diff changeset
617 * an allocation of a new buffer and copying the previous contents.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
618 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
619 * @param json the json interface
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
620 * @param str the source string
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
621 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
622 * @retval non-zero internal allocation error
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
623 * @see cxJsonFilln()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
624 */
974
ed44741d8ab5 fix copy-pasted parameter name
Mike Becker <universe@uap-core.de>
parents: 973
diff changeset
625 #define cxJsonFill(json, str) _Generic((str), \
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
626 cxstring: cx_json_fill_cxstr, \
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
627 cxmutstr: cx_json_fill_mutstr, \
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
628 char*: cx_json_fill_str, \
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
629 const char*: cx_json_fill_str) \
974
ed44741d8ab5 fix copy-pasted parameter name
Mike Becker <universe@uap-core.de>
parents: 973
diff changeset
630 (json, str)
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
631
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
632 /**
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
633 * @copydoc cxJsonFill()
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
634 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
635 cx_attr_nonnull
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
636 static inline int cx_json_fill_cxstr(
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
637 CxJson *json,
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
638 cxstring str
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
639 ) {
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
640 return cxJsonFilln(json, str.ptr, str.length);
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
641 }
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
642
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
643 /**
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
644 * @copydoc cxJsonFill()
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
645 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
646 cx_attr_nonnull
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
647 static inline int cx_json_fill_mutstr(
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
648 CxJson *json,
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
649 cxmutstr str
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
650 ) {
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
651 return cxJsonFilln(json, str.ptr, str.length);
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
652 }
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
653
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
654 /**
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
655 * @copydoc cxJsonFill()
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
656 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
657 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
658 cx_attr_cstr_arg(2)
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
659 static inline int cx_json_fill_str(
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
660 CxJson *json,
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
661 const char *str
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
662 ) {
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
663 return cxJsonFilln(json, str, strlen(str));
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
664 }
988
15b3ca7ee33f make ucx C++ compatible again (and add tests for it) - fixes #486
Mike Becker <universe@uap-core.de>
parents: 985
diff changeset
665 #endif
973
05910a8994f7 add UCX string support to cxJsonFill()
Mike Becker <universe@uap-core.de>
parents: 967
diff changeset
666
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
667 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
668 * Creates a new (empty) JSON object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
669 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
670 * @param allocator the allocator to use
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
671 * @return the new JSON object or @c NULL if allocation fails
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
672 * @see cxJsonObjPutObj()
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
673 * @see cxJsonArrAddValues()
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
674 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
675 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
676 CxJsonValue* cxJsonCreateObj(const CxAllocator* allocator);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
677
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
678 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
679 * Creates a new (empty) JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
680 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
681 * @param allocator the allocator to use
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
682 * @return the new JSON array or @c NULL if allocation fails
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
683 * @see cxJsonObjPutArr()
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
684 * @see cxJsonArrAddValues()
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
685 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
686 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
687 CxJsonValue* cxJsonCreateArr(const CxAllocator* allocator);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
688
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
689 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
690 * Creates a new JSON number value.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
691 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
692 * @param allocator the allocator to use
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
693 * @param num the numeric value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
694 * @return the new JSON value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
695 * @see cxJsonObjPutNumber()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
696 * @see cxJsonArrAddNumbers()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
697 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
698 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
699 CxJsonValue* cxJsonCreateNumber(const CxAllocator* allocator, double num);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
700
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
701 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
702 * Creates a new JSON number value based on an integer.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
703 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
704 * @param allocator the allocator to use
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
705 * @param num the numeric value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
706 * @return the new JSON value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
707 * @see cxJsonObjPutInteger()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
708 * @see cxJsonArrAddIntegers()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
709 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
710 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
711 CxJsonValue* cxJsonCreateInteger(const CxAllocator* allocator, int64_t num);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
712
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
713 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
714 * Creates a new JSON string.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
715 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
716 * @param allocator the allocator to use
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
717 * @param str the string data
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
718 * @return the new JSON value or @c NULL if allocation fails
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
719 * @see cxJsonCreateString()
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
720 * @see cxJsonObjPutString()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
721 * @see cxJsonArrAddStrings()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
722 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
723 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
724 cx_attr_nonnull_arg(2)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
725 cx_attr_cstr_arg(2)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
726 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, const char *str);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
727
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
728 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
729 * Creates a new JSON string.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
730 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
731 * @param allocator the allocator to use
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
732 * @param str the string data
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
733 * @return the new JSON value or @c NULL if allocation fails
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
734 * @see cxJsonCreateCxString()
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
735 * @see cxJsonObjPutCxString()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
736 * @see cxJsonArrAddCxStrings()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
737 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
738 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
739 CxJsonValue* cxJsonCreateCxString(const CxAllocator* allocator, cxstring str);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
740
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
741 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
742 * Creates a new JSON literal.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
743 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
744 * @param allocator the allocator to use
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
745 * @param lit the type of literal
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
746 * @return the new JSON value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
747 * @see cxJsonObjPutLiteral()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
748 * @see cxJsonArrAddLiterals()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
749 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
750 cx_attr_nodiscard
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
751 CxJsonValue* cxJsonCreateLiteral(const CxAllocator* allocator, CxJsonLiteral lit);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
752
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
753 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
754 * Adds number values to a JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
755 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
756 * @param arr the JSON array
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
757 * @param num the array of values
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
758 * @param count the number of elements
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
759 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
760 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
761 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
762 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
763 cx_attr_access_r(2, 3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
764 int cxJsonArrAddNumbers(CxJsonValue* arr, const double* num, size_t count);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
765
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
766 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
767 * Adds number values, of which all are integers, to a JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
768 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
769 * @param arr the JSON array
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
770 * @param num the array of values
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
771 * @param count the number of elements
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
772 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
773 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
774 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
775 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
776 cx_attr_access_r(2, 3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
777 int cxJsonArrAddIntegers(CxJsonValue* arr, const int64_t* num, size_t count);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
778
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
779 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
780 * Adds strings to a JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
781 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
782 * The strings will be copied with the allocator of the array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
783 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
784 * @param arr the JSON array
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
785 * @param str the array of strings
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
786 * @param count the number of elements
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
787 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
788 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
789 * @see cxJsonArrAddCxStrings()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
790 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
791 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
792 cx_attr_access_r(2, 3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
793 int cxJsonArrAddStrings(CxJsonValue* arr, const char* const* str, size_t count);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
794
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
795 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
796 * Adds strings to a JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
797 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
798 * The strings will be copied with the allocator of the array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
799 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
800 * @param arr the JSON array
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
801 * @param str the array of strings
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
802 * @param count the number of elements
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
803 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
804 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
805 * @see cxJsonArrAddStrings()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
806 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
807 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
808 cx_attr_access_r(2, 3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
809 int cxJsonArrAddCxStrings(CxJsonValue* arr, const cxstring* str, size_t count);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
810
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
811 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
812 * Adds literals to a JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
813 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
814 * @param arr the JSON array
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
815 * @param lit the array of literal types
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
816 * @param count the number of elements
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
817 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
818 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
819 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
820 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
821 cx_attr_access_r(2, 3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
822 int cxJsonArrAddLiterals(CxJsonValue* arr, const CxJsonLiteral* lit, size_t count);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
823
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
824 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
825 * Add arbitrary values to a JSON array.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
826 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
827 * @attention In contrast to all other add functions, this function adds the values
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
828 * directly to the array instead of copying them.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
829 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
830 * @param arr the JSON array
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
831 * @param val the values
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
832 * @param count the number of elements
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
833 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
834 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
835 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
836 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
837 cx_attr_access_r(2, 3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
838 int cxJsonArrAddValues(CxJsonValue* arr, CxJsonValue* const* val, size_t count);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
839
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
840 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
841 * Adds or replaces a value within a JSON object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
842 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
843 * The value will be directly added and not copied.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
844 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
845 * @note If a value with the specified @p name already exists,
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
846 * it will be (recursively) freed with its own allocator.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
847 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
848 * @param obj the JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
849 * @param name the name of the value
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
850 * @param child the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
851 * @retval zero success
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
852 * @retval non-zero allocation failure
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
853 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
854 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
855 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
856
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
857 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
858 * Creates a new JSON object and adds it to an existing object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
859 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
860 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
861 * @param name the name of the new value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
862 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
863 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
864 * @see cxJsonCreateObj()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
865 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
866 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
867 CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
868
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
869 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
870 * Creates a new JSON array and adds it to an object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
871 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
872 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
873 * @param name the name of the new value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
874 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
875 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
876 * @see cxJsonCreateArr()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
877 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
878 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
879 CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
880
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
881 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
882 * Creates a new JSON number and adds it to an object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
883 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
884 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
885 * @param name the name of the new value
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
886 * @param num the numeric value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
887 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
888 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
889 * @see cxJsonCreateNumber()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
890 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
891 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
892 CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, cxstring name, double num);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
893
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
894 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
895 * Creates a new JSON number, based on an integer, and adds it to an object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
896 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
897 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
898 * @param name the name of the new value
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
899 * @param num the numeric value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
900 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
901 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
902 * @see cxJsonCreateInteger()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
903 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
904 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
905 CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, cxstring name, int64_t num);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
906
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
907 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
908 * Creates a new JSON string and adds it to an object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
909 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
910 * The string data is copied.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
911 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
912 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
913 * @param name the name of the new value
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
914 * @param str the string data
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
915 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
916 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
917 * @see cxJsonCreateString()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
918 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
919 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
920 cx_attr_cstr_arg(3)
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
921 CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, cxstring name, const char* str);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
922
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
923 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
924 * Creates a new JSON string and adds it to an object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
925 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
926 * The string data is copied.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
927 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
928 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
929 * @param name the name of the new value
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
930 * @param str the string data
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
931 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
932 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
933 * @see cxJsonCreateCxString()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
934 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
935 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
936 CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, cxstring name, cxstring str);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
937
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
938 /**
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
939 * Creates a new JSON literal and adds it to an object.
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
940 *
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
941 * @param obj the target JSON object
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
942 * @param name the name of the new value
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
943 * @param lit the type of literal
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
944 * @return the new value or @c NULL if allocation fails
1056
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
945 * @see cxJsonObjPut()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
946 * @see cxJsonCreateLiteral()
e180bd389fbc add documentation for json value creation API
Mike Becker <universe@uap-core.de>
parents: 1054
diff changeset
947 */
1054
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
948 cx_attr_nonnull
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
949 CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, cxstring name, CxJsonLiteral lit);
fb1076ead56f add implementation for creating new json values
Mike Becker <universe@uap-core.de>
parents: 1042
diff changeset
950
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
951 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
952 * Recursively deallocates the memory of a JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
953 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
954 * @remark The type of each deallocated value will be changed
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
955 * to #CX_JSON_NOTHING and values of such type will be skipped
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
956 * by the de-allocation. That means, this function protects
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
957 * you from double-frees when you are accidentally freeing
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
958 * a nested value and then the parent value (or vice versa).
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
959 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
960 * @param value the value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
961 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
962 void cxJsonValueFree(CxJsonValue *value);
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
963
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
964 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
965 * Tries to obtain the next JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
966 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
967 * Before this function can be called, the input buffer needs
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
968 * to be filled with cxJsonFill().
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
969 *
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
970 * When this function returns #CX_JSON_INCOMPLETE_DATA, you can
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
971 * add the missing data with another invocation of cxJsonFill()
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
972 * and then repeat the call to cxJsonNext().
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
973 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
974 * @param json the json interface
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
975 * @param value a pointer where the next value shall be stored
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
976 * @retval CX_JSON_NO_ERROR successfully retrieve the @p value
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
977 * @retval CX_JSON_NO_DATA there is no (more) data in the buffer to read from
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
978 * @retval CX_JSON_INCOMPLETE_DATA an incomplete value was read
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
979 * and more data needs to be filled
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
980 * @retval CX_JSON_NULL_DATA the buffer was never initialized
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
981 * @retval CX_JSON_BUFFER_ALLOC_FAILED allocating internal buffer space failed
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
982 * @retval CX_JSON_VALUE_ALLOC_FAILED allocating memory for a CxJsonValue failed
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
983 * @retval CX_JSON_FORMAT_ERROR_NUMBER the JSON text contains an illegally formatted number
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
984 * @retval CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN JSON syntax error
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
985 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
986 cx_attr_nonnull
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
987 cx_attr_access_w(2)
1002
1483c47063a8 add status codes to json parser - relates to #431
Mike Becker <universe@uap-core.de>
parents: 1000
diff changeset
988 CxJsonStatus cxJsonNext(CxJson *json, CxJsonValue **value);
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
989
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
990 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
991 * Checks if the specified value is a JSON object.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
992 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
993 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
994 * @retval true the value is a JSON object
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
995 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
996 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
997 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
998 static inline bool cxJsonIsObject(const CxJsonValue *value) {
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
999 return value->type == CX_JSON_OBJECT;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1000 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1001
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1002 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1003 * Checks if the specified value is a JSON array.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1004 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1005 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1006 * @retval true the value is a JSON array
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1007 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1008 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1009 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1010 static inline bool cxJsonIsArray(const CxJsonValue *value) {
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1011 return value->type == CX_JSON_ARRAY;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1012 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1013
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1014 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1015 * Checks if the specified value is a string.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1016 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1017 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1018 * @retval true the value is a string
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1019 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1020 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1021 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1022 static inline bool cxJsonIsString(const CxJsonValue *value) {
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1023 return value->type == CX_JSON_STRING;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1024 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1025
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1026 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1027 * Checks if the specified value is a JSON number.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1028 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1029 * This function will return true for both floating point and
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1030 * integer numbers.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1031 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1032 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1033 * @retval true the value is a JSON number
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1034 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1035 * @see cxJsonIsInteger()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1036 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1037 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1038 static inline bool cxJsonIsNumber(const CxJsonValue *value) {
966
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1039 return value->type == CX_JSON_NUMBER || value->type == CX_JSON_INTEGER;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1040 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1041
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1042 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1043 * Checks if the specified value is an integer number.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1044 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1045 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1046 * @retval true the value is an integer number
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1047 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1048 * @see cxJsonIsNumber()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1049 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1050 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1051 static inline bool cxJsonIsInteger(const CxJsonValue *value) {
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1052 return value->type == CX_JSON_INTEGER;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1053 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1054
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1055 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1056 * Checks if the specified value is a JSON literal.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1057 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1058 * JSON literals are @c true, @c false, and @c null.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1059 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1060 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1061 * @retval true the value is a JSON literal
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1062 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1063 * @see cxJsonIsTrue()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1064 * @see cxJsonIsFalse()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1065 * @see cxJsonIsNull()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1066 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1067 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1068 static inline bool cxJsonIsLiteral(const CxJsonValue *value) {
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1069 return value->type == CX_JSON_LITERAL;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1070 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1071
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1072 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1073 * Checks if the specified value is a Boolean literal.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1074 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1075 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1076 * @retval true the value is either @c true or @c false
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1077 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1078 * @see cxJsonIsTrue()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1079 * @see cxJsonIsFalse()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1080 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1081 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1082 static inline bool cxJsonIsBool(const CxJsonValue *value) {
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
1083 return cxJsonIsLiteral(value) && value->value.literal != CX_JSON_NULL;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1084 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1085
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1086 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1087 * Checks if the specified value is @c true.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1088 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1089 * @remark Be advised, that this is not the same as
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1090 * testing @c !cxJsonIsFalse(v).
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1091 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1092 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1093 * @retval true the value is @c true
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1094 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1095 * @see cxJsonIsBool()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1096 * @see cxJsonIsFalse()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1097 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1098 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1099 static inline bool cxJsonIsTrue(const CxJsonValue *value) {
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
1100 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_TRUE;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1101 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1102
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1103 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1104 * Checks if the specified value is @c false.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1105 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1106 * @remark Be advised, that this is not the same as
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1107 * testing @c !cxJsonIsTrue(v).
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1108 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1109 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1110 * @retval true the value is @c false
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1111 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1112 * @see cxJsonIsBool()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1113 * @see cxJsonIsTrue()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1114 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1115 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1116 static inline bool cxJsonIsFalse(const CxJsonValue *value) {
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
1117 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_FALSE;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1118 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1119
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1120 /**
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1121 * Checks if the specified value is @c null.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1122 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1123 * @param value a pointer to the value
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1124 * @retval true the value is @c null
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1125 * @retval false otherwise
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1126 * @see cxJsonIsLiteral()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1127 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1128 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1129 static inline bool cxJsonIsNull(const CxJsonValue *value) {
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
1130 return cxJsonIsLiteral(value) && value->value.literal == CX_JSON_NULL;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1131 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1132
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1133 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1134 * Obtains a C string from the given JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1135 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1136 * If the @p value is not a string, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1137 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1138 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1139 * @return the value represented as C string
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1140 * @see cxJsonIsString()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1141 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1142 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1143 cx_attr_returns_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1144 static inline char *cxJsonAsString(const CxJsonValue *value) {
966
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1145 return value->value.string.ptr;
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1146 }
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1147
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1148 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1149 * Obtains a UCX string from the given JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1150 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1151 * If the @p value is not a string, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1152 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1153 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1154 * @return the value represented as UCX string
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1155 * @see cxJsonIsString()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1156 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1157 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1158 static inline cxstring cxJsonAsCxString(const CxJsonValue *value) {
966
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1159 return cx_strcast(value->value.string);
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1160 }
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1161
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1162 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1163 * Obtains a mutable UCX string from the given JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1164 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1165 * If the @p value is not a string, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1166 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1167 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1168 * @return the value represented as mutable UCX string
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1169 * @see cxJsonIsString()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1170 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1171 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1172 static inline cxmutstr cxJsonAsCxMutStr(const CxJsonValue *value) {
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1173 return value->value.string;
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1174 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1175
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1176 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1177 * Obtains a double-precision floating point value from the given JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1178 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1179 * If the @p value is not a JSON number, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1180 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1181 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1182 * @return the value represented as double
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1183 * @see cxJsonIsNumber()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1184 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1185 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1186 static inline double cxJsonAsDouble(const CxJsonValue *value) {
966
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1187 if (value->type == CX_JSON_INTEGER) {
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1188 return (double) value->value.integer;
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1189 } else {
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1190 return value->value.number;
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1191 }
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1192 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1193
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1194 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1195 * Obtains a 64-bit signed integer from the given JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1196 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1197 * If the @p value is not a JSON number, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1198 * If it is a JSON number, but not an integer, the value will be
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1199 * converted to an integer, possibly losing precision.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1200 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1201 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1202 * @return the value represented as double
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1203 * @see cxJsonIsNumber()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1204 * @see cxJsonIsInteger()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1205 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1206 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1207 static inline int64_t cxJsonAsInteger(const CxJsonValue *value) {
966
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1208 if (value->type == CX_JSON_INTEGER) {
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1209 return value->value.integer;
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1210 } else {
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1211 return (int64_t) value->value.number;
1aa7ec3e46e7 treat integers and doubles both as JSON numbers
Mike Becker <universe@uap-core.de>
parents: 965
diff changeset
1212 }
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1213 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1214
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1215 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1216 * Obtains a Boolean value from the given JSON value.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1217 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1218 * If the @p value is not a JSON literal, the behavior is undefined.
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1219 * The @c null literal is interpreted as @c false.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1220 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1221 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1222 * @return the value represented as double
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1223 * @see cxJsonIsLiteral()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1224 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1225 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1226 static inline bool cxJsonAsBool(const CxJsonValue *value) {
965
dfdfedbe2c86 remove single-member structs
Mike Becker <universe@uap-core.de>
parents: 954
diff changeset
1227 return value->value.literal == CX_JSON_TRUE;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1228 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1229
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1230 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1231 * Returns the size of a JSON array.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1232 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1233 * If the @p value is not a JSON array, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1234 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1235 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1236 * @return the size of the array
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1237 * @see cxJsonIsArray()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1238 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1239 cx_attr_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1240 static inline size_t cxJsonArrSize(const CxJsonValue *value) {
967
a58f602ed2fe simplify parsing of array and object elements
Mike Becker <universe@uap-core.de>
parents: 966
diff changeset
1241 return value->value.array.array_size;
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1242 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1243
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1244 /**
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1245 * Returns an element from a JSON array.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1246 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1247 * If the @p value is not a JSON array, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1248 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1249 * This function guarantees to return a value. If the index is
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1250 * out of bounds, the returned value will be of type
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1251 * #CX_JSON_NOTHING, but never @c NULL.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1252 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1253 * @param value the JSON value
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1254 * @param index the index in the array
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1255 * @return the value at the specified index
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1256 * @see cxJsonIsArray()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1257 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1258 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1259 cx_attr_returns_nonnull
1009
7650e722437e minor cleanup
Mike Becker <universe@uap-core.de>
parents: 1007
diff changeset
1260 CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index);
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1261
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1262 /**
1033
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1263 * Returns an iterator over the JSON array elements.
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1264 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1265 * The iterator yields values of type @c CxJsonValue* .
1033
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1266 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1267 * If the @p value is not a JSON array, the behavior is undefined.
1033
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1268 *
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1269 * @param value the JSON value
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1270 * @return an iterator over the array elements
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1271 * @see cxJsonIsArray()
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1272 */
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1273 cx_attr_nonnull
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1274 cx_attr_nodiscard
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1275 CxIterator cxJsonArrIter(const CxJsonValue *value);
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1276
e3009345984b add cxJsonArrIter() - fixes #524
Mike Becker <universe@uap-core.de>
parents: 1013
diff changeset
1277 /**
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1278 * Returns an iterator over the JSON object members.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1279 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1280 * The iterator yields values of type @c CxJsonObjValue* which
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1281 * contain the name and value of the member.
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1282 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1283 * If the @p value is not a JSON object, the behavior is undefined.
1072
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1284 *
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1285 * @param value the JSON value
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1286 * @return an iterator over the object members
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1287 * @see cxJsonIsObject()
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1288 */
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1289 cx_attr_nonnull
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1290 cx_attr_nodiscard
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1291 CxIterator cxJsonObjIter(const CxJsonValue *value);
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1292
c89283cd559b first mvp for the json writer - relates to #526
Mike Becker <universe@uap-core.de>
parents: 1067
diff changeset
1293 /**
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1294 * @copydoc cxJsonObjGet()
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1295 */
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1296 cx_attr_nonnull
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1297 cx_attr_returns_nonnull
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1298 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name);
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1299
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1300 #ifdef __cplusplus
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1301 } // extern "C"
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1302
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1303 CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) {
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1304 return cx_json_obj_get_cxstr(value, name);
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1305 }
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1306
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1307 CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) {
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1308 return cx_json_obj_get_cxstr(value, cx_strcast(name));
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1309 }
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1310
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1311 CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) {
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1312 return cx_json_obj_get_cxstr(value, cx_str(name));
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1313 }
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1314
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1315 extern "C" {
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1316 #else
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1317 /**
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1318 * Returns a value corresponding to a key in a JSON object.
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1319 *
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1320 * If the @p value is not a JSON object, the behavior is undefined.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1321 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1322 * This function guarantees to return a JSON value. If the
1097
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1323 * object does not contain @p name, the returned JSON value
ef4a6cb318ec refine docs for json.h - issue #548
Mike Becker <universe@uap-core.de>
parents: 1082
diff changeset
1324 * will be of type #CX_JSON_NOTHING, but never @c NULL.
1012
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1325 *
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1326 * @param value the JSON object
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1327 * @param name the key to look up
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1328 * @return the value corresponding to the key
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1329 * @see cxJsonIsObject()
21884374edbb add documentation - resolves #431
Mike Becker <universe@uap-core.de>
parents: 1009
diff changeset
1330 */
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1331 #define cxJsonObjGet(value, name) _Generic((name), \
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1332 cxstring: cx_json_obj_get_cxstr, \
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1333 cxmutstr: cx_json_obj_get_mutstr, \
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1334 char*: cx_json_obj_get_str, \
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1335 const char*: cx_json_obj_get_str) \
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1336 (value, name)
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1337
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1338 /**
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1339 * @copydoc cxJsonObjGet()
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1340 */
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1341 cx_attr_nonnull
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1342 cx_attr_returns_nonnull
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1343 static inline CxJsonValue *cx_json_obj_get_mutstr(const CxJsonValue *value, cxmutstr name) {
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1344 return cx_json_obj_get_cxstr(value, cx_strcast(name));
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1345 }
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1346
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1347 /**
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1348 * @copydoc cxJsonObjGet()
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1349 */
985
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1350 cx_attr_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1351 cx_attr_returns_nonnull
68754c7de906 major refactoring of attributes
Mike Becker <universe@uap-core.de>
parents: 974
diff changeset
1352 cx_attr_cstr_arg(2)
1037
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1353 static inline CxJsonValue *cx_json_obj_get_str(const CxJsonValue *value, const char *name) {
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1354 return cx_json_obj_get_cxstr(value, cx_str(name));
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1355 }
83620ba72cc1 generify cxJsonObjGet() - fixes #525
Mike Becker <universe@uap-core.de>
parents: 1033
diff changeset
1356 #endif
937
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1357
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1358 #ifdef __cplusplus
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1359 }
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1360 #endif
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1361
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1362 #endif /* UCX_JSON_H */
10123f4d5618 add first draft of json implementation - relates to #431
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1363

mercurial