-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSON_parser.h
executable file
·114 lines (96 loc) · 2.77 KB
/
JSON_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef JSON_PARSER_H
#define JSON_PARSER_H
/* JSON_parser.h */
#include <stddef.h>
/* Windoze testing not completed yet!! */
#ifdef JSON_PARSER_DLL
# ifdef _MSC_VER
# ifdef JSON_PARSER_DLL_EXPORTS
# define JSON_PARSER_DLL_API __declspec(dllexport)
# else
# define JSON_PARSER_DLL_API __declspec(dllimport)
# endif
# else
# define JSON_PARSER_DLL_API
# endif
#else
# define JSON_PARSER_DLL_API
#endif
/* Non-floating point values */
#if __STDC_VERSION__ >= 199901L || HAVE_LONG_LONG == 1
typedef long long JSON_int_t;
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%lld"
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%lld"
#else
typedef long JSON_int_t;
#define JSON_PARSER_INTEGER_SSCANF_TOKEN "%ld"
#define JSON_PARSER_INTEGER_SPRINTF_TOKEN "%ld"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
JSON_E_NONE = 0,
JSON_E_INVALID_CHAR,
JSON_E_INVALID_KEYWORD,
JSON_E_INVALID_ESCAPE_SEQUENCE,
JSON_E_INVALID_UNICODE_SEQUENCE,
JSON_E_INVALID_NUMBER,
JSON_E_NESTING_DEPTH_REACHED,
JSON_E_UNBALANCED_COLLECTION,
JSON_E_EXPECTED_KEY,
JSON_E_EXPECTED_COLON,
JSON_E_OUT_OF_MEMORY
} JSON_error;
typedef enum
{
JSON_T_NONE = 0,
JSON_T_ARRAY_BEGIN,
JSON_T_ARRAY_END,
JSON_T_OBJECT_BEGIN,
JSON_T_OBJECT_END,
JSON_T_INTEGER,
JSON_T_FLOAT,
JSON_T_NULL,
JSON_T_TRUE,
JSON_T_FALSE,
JSON_T_STRING,
JSON_T_KEY,
JSON_T_MAX
} JSON_type;
typedef struct JSON_value_struct {
union {
JSON_int_t integer_value;
double float_value;
struct {
const char* value;
size_t length;
} str;
} vu;
} JSON_value;
typedef struct JSON_parser_struct* JSON_parser;
typedef int (*JSON_parser_callback)(void* ctx, int type, const JSON_value* value);
typedef void* (*JSON_malloc_t)(size_t n);
typedef void (*JSON_free_t)(void* mem);
typedef struct {
JSON_parser_callback callback;
void* callback_ctx;
int depth;
int allow_comments;
int handle_floats_manually;
JSON_malloc_t malloc;
JSON_free_t free;
} JSON_config;
JSON_PARSER_DLL_API void init_JSON_config(JSON_config * config);
JSON_PARSER_DLL_API JSON_parser new_JSON_parser(JSON_config const* config);
JSON_PARSER_DLL_API void delete_JSON_parser(JSON_parser jc);
JSON_PARSER_DLL_API int JSON_parser_char(JSON_parser jc, int next_char);
JSON_PARSER_DLL_API int JSON_parser_done(JSON_parser jc);
JSON_PARSER_DLL_API int JSON_parser_is_legal_white_space_string(const char* s);
JSON_PARSER_DLL_API int JSON_parser_get_last_error(JSON_parser jc);
JSON_PARSER_DLL_API int JSON_parser_reset(JSON_parser jc);
#ifdef __cplusplus
}
#endif
#endif /* JSON_PARSER_H */