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