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