2 Copyright (C) 2006 Georgia Public Library Service
3 Bill Erickson <billserickson@gmail.com>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
17 /* ----------------------------------------------------------------------- */
18 /* Clients need not include this file. These are internal utilities only */
19 /* ----------------------------------------------------------------------- */
21 #define JSON_EAT_WS(ctx) \
22 while( ctx->index < ctx->chunksize ) { \
23 if(!isspace(ctx->chunk[ctx->index])) break; \
26 if( ctx->index >= ctx->chunksize ) return 0; \
27 c = ctx->chunk[ctx->index];
29 #define JSON_CACHE_DATA(ctx, buf, size) \
30 while( (buf->n_used < size) && (ctx->index < ctx->chunksize) ) \
31 buffer_add_char(buf, ctx->chunk[ctx->index++]);
33 #define JSON_LOG_MARK __FILE__,__LINE__
35 #define JSON_NUMBER_CHARS "0123456789.+-eE"
38 * These are the callbacks through which the top level parser
39 * builds objects via the push parser
41 void _jsonHandleStartObject(void*);
42 void _jsonHandleObjectKey(void*, char* key);
43 void _jsonHandleEndObject(void*);
44 void _jsonHandleStartArray(void*);
45 void _jsonHandleEndArray(void*);
46 void _jsonHandleNull(void*);
47 void _jsonHandleString(void*, char* string);
48 void _jsonHandleBool(void*, int boolval);
49 void _jsonHandleNumber(void*, double num);
50 void _jsonHandleError(void*, char* str, ...);
52 struct jsonInternalParserStruct {
53 jsonParserContext* ctx;
57 void (*handleError) (const char*);
59 typedef struct jsonInternalParserStruct jsonInternalParser;
61 jsonInternalParser* _jsonNewInternalParser();
62 void _jsonInternalParserFree(jsonInternalParser* p);
65 * Calls the defined error handler with the given error message.
68 int _jsonParserError( jsonParserContext* ctx, char* err, ... );
73 * @return 0 on continue, 1 if it goes past the end of the string, -1 on error
75 int _jsonParserHandleUnicode( jsonParserContext* ctx );
79 * @param type 0 for null, 1 for true, 2 for false
80 * @return 0 on continue, 1 if it goes past the end of the string, -1 on error
82 int _jsonParserHandleMatch( jsonParserContext* ctx, int type );
85 * @return 0 on continue, 1 on end of chunk, -1 on error
87 int _jsonParserHandleString( jsonParserContext* ctx );
90 * @return 0 on continue, 1 on end of chunk, -1 on error
92 int _jsonParserHandleNumber( jsonParserContext* ctx );
95 void _jsonInsertParserItem( jsonInternalParser* p, jsonObject* newo );
98 /* Utility method. finds any object in the tree that matches the path.
99 Use this for finding paths that start with '//' */
100 jsonObject* _jsonObjectFindPathRecurse( const jsonObject* o, char* root, char* path );
103 /* returns a list of object whose key is 'root'. These are used as
104 potential objects when doing a // search */
105 jsonObject* __jsonObjectFindPathRecurse( const jsonObject* o, char* root );