]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/objson/json_parser.h
adding early custom json code
[OpenSRF.git] / src / objson / json_parser.h
1 /* ---------------------------------------------------------------------------------------
2         JSON parser.
3  * --------------------------------------------------------------------------------------- */
4
5
6 #include <stdio.h>
7 #include "object.h"
8 #include "utils.h"
9
10 #ifndef JSON_PARSER_H
11 #define JSON_PARSER_H
12
13
14
15
16 /* returns NULL on error.  if string is NULL, returns an object whose is_null flag  
17  * is set to true */
18 object* json_parse_string(char* string);
19
20 /* does the actual parsing work.  returns 0 on success.  -1 on error and
21  * -2 if there was no object to build (string was all comments) 
22  */
23 int _json_parse_string(char* string, unsigned long* index, object* obj);
24
25 /* returns 0 on success and turns obj into a string object */
26 int json_parse_json_string(char* string, unsigned long* index, object* obj);
27
28 /* returns 0 on success and turns obj into a number or double object */
29 int json_parse_json_number(char* string, unsigned long* index, object* obj);
30
31 int json_parse_json_object(char* string, unsigned long* index, object* obj);
32
33 /* returns 0 on success and turns object into an array object */
34 int json_parse_json_array(char* string, unsigned long* index, object* obj);
35
36 /* churns through whitespace and increments index as it goes.
37  * eat_all means we should eat newlines, tabs
38  */
39 void json_eat_ws(char* string, unsigned long* index, int eat_all);
40
41 int json_parse_json_bool(char* string, unsigned long* index, object* obj);
42
43 /* removes comments from a json string.  if the comment contains a class hint
44  * and class_hint isn't NULL, an allocated char* with the class name will be
45  * shoved into *class_hint.  returns 0 on success, -1 on parse error.
46  * 'index' is assumed to be at the second character (*) of the comment
47  */
48 int json_eat_comment(char* string, unsigned long* index, char** class_hint, int parse_class);
49
50 /* prints a useful error message to stderr. always returns -1 */
51 int json_handle_error(char* string, unsigned long* index, char* err_msg);
52
53 /* returns true if c is 0-9 */
54 int is_number(char c);
55
56 int json_parse_json_null(char* string, unsigned long* index, object* obj);
57
58
59 #endif