]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/objson/json_parser.h
ede5d91c55f59e9d6b7ce109680c221b6912bc1a
[OpenSRF.git] / include / objson / json_parser.h
1 /*
2 Copyright (C) 2005  Georgia Public Library Service 
3 Bill Erickson <highfalutin@gmail.com>
4
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.
9
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.
14 */
15
16
17
18
19 /* ---------------------------------------------------------------------------------------
20         JSON parser.
21  * --------------------------------------------------------------------------------------- */
22 #ifndef JSON_PARSER_H
23 #define JSON_PARSER_H
24
25 #include <stdio.h>
26 #include <objson/object.h>
27 #include <opensrf/utils.h>
28
29
30
31 /* Parses the given JSON string and returns the built object. 
32  *      returns NULL (and prints parser error to stderr) on error.  
33  */
34
35 jsonObject* json_parse_string(char* string);
36
37 jsonObject* jsonParseString(char* string);
38 jsonObject* jsonParseStringFmt( char* string, ... );
39
40 jsonObject* json_parse_file( const char* filename );
41
42 jsonObject* jsonParseFile( const char* string );
43
44
45
46 /* does the actual parsing work.  returns 0 on success.  -1 on error and
47  * -2 if there was no object to build (string was all comments) 
48  */
49 int _json_parse_string(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
50
51 /* returns 0 on success and turns obj into a string object */
52 int json_parse_json_string(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
53
54 /* returns 0 on success and turns obj into a number or double object */
55 int json_parse_json_number(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
56
57 /* returns 0 on success and turns obj into an 'object' object */
58 int json_parse_json_object(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
59
60 /* returns 0 on success and turns object into an array object */
61 int json_parse_json_array(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
62
63 /* churns through whitespace and increments index as it goes.
64  * eat_all == true means we should eat newlines, tabs
65  */
66 void json_eat_ws(char* string, unsigned long* index, int eat_all, int current_strlen);
67
68 int json_parse_json_bool(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
69
70 /* removes comments from a json string.  if the comment contains a class hint
71  * and class_hint isn't NULL, an allocated char* with the class name will be
72  * shoved into *class_hint.  returns 0 on success, -1 on parse error.
73  * 'index' is assumed to be at the second character (*) of the comment
74  */
75 int json_eat_comment(char* string, unsigned long* index, char** class_hint, int parse_class, int current_strlen);
76
77 /* prints a useful error message to stderr. always returns -1 */
78 int json_handle_error(char* string, unsigned long* index, char* err_msg);
79
80 /* returns true if c is 0-9 */
81 int is_number(char c);
82
83 int json_parse_json_null(char* string, unsigned long* index, jsonObject* obj, int current_strlen);
84
85
86 #endif