src/cx/json.h

changeset 1002
1483c47063a8
parent 1000
1aecddf7e209
child 1007
81b2986d2b04
equal deleted inserted replaced
1001:5c9ec5a0a4ef 1002:1483c47063a8
121 } value; 121 } value;
122 }; 122 };
123 123
124 struct cx_json_token_s { 124 struct cx_json_token_s {
125 CxJsonTokenType tokentype; 125 CxJsonTokenType tokentype;
126 const char *content; 126 bool allocated;
127 size_t length; 127 cxmutstr content;
128 size_t alloc;
129 }; 128 };
130 129
131 struct cx_json_s { 130 struct cx_json_s {
132 const CxAllocator *allocator; 131 const CxAllocator *allocator;
133 const char *buffer; 132 const char *buffer;
164 CxJsonValue* vbuf_internal[8]; 163 CxJsonValue* vbuf_internal[8];
165 164
166 int error; // TODO: currently unused 165 int error; // TODO: currently unused
167 bool tokenizer_escape; // TODO: check if it can be replaced with look-behind 166 bool tokenizer_escape; // TODO: check if it can be replaced with look-behind
168 }; 167 };
168
169 /**
170 * Status codes for the json interface.
171 */
172 enum cx_json_status {
173 /**
174 * Everything is fine.
175 */
176 CX_JSON_NO_ERROR,
177 /**
178 * The input buffer does not contain more data.
179 */
180 CX_JSON_NO_DATA,
181 /**
182 * The input ends unexpectedly.
183 *
184 * Refill the buffer with cxJsonFill() to complete the json data.
185 */
186 CX_JSON_INCOMPLETE_DATA,
187 /**
188 * Not used as a status and never returned by any function.
189 *
190 * You can use this enumerator to check for all "good" status results
191 * by checking if the status is less than \c CX_JSON_OK.
192 *
193 * A "good" status means, that you can refill data and continue parsing.
194 */
195 CX_JSON_OK,
196 /**
197 * Input buffer is \c NULL.
198 */
199 CX_JSON_NULL_INPUT,
200 /**
201 * Allocating memory for the internal buffer failed.
202 */
203 CX_JSON_BUFFER_ALLOC_FAILED,
204 /**
205 * Allocating memory for a json value failed.
206 */
207 CX_JSON_VALUE_ALLOC_FAILED,
208 /**
209 * A number value is incorrectly formatted.
210 */
211 CX_JSON_FORMAT_ERROR_NUMBER,
212 /**
213 * The tokenizer found something unexpected.
214 */
215 CX_JSON_FORMAT_ERROR_UNEXPECTED_TOKEN
216 };
217
218 /**
219 * Typedef for the json status enum.
220 */
221 typedef enum cx_json_status CxJsonStatus;
169 222
170 cx_attr_nonnull_arg(1) 223 cx_attr_nonnull_arg(1)
171 void cxJsonInit(CxJson *json, const CxAllocator *allocator); 224 void cxJsonInit(CxJson *json, const CxAllocator *allocator);
172 225
173 cx_attr_nonnull 226 cx_attr_nonnull
241 #endif 294 #endif
242 295
243 void cxJsonValueFree(CxJsonValue *value); 296 void cxJsonValueFree(CxJsonValue *value);
244 297
245 cx_attr_nonnull 298 cx_attr_nonnull
246 int cxJsonNext(CxJson *json, CxJsonValue **value); 299 CxJsonStatus cxJsonNext(CxJson *json, CxJsonValue **value);
247 300
248 cx_attr_nonnull 301 cx_attr_nonnull
249 static inline bool cxJsonIsObject(CxJsonValue *value) { 302 static inline bool cxJsonIsObject(CxJsonValue *value) {
250 return value->type == CX_JSON_OBJECT; 303 return value->type == CX_JSON_OBJECT;
251 } 304 }

mercurial