-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminijson.h
76 lines (61 loc) · 1.38 KB
/
minijson.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
#ifndef MINIJSON_H
#define MINIJSON_H
#include <stddef.h> /* size_t */
typedef enum
{
MJ_NULL,
MJ_FALSE,
MJ_TRUE,
MJ_NUMBER,
MJ_STRING,
MJ_ARRAY,
MJ_OBJECT
}MJ_type;
typedef struct MJ_value MJ_value;
typedef struct MJ_value
{
union
{
struct
{
MJ_value *e;
size_t size;
}a; /* array */
struct
{
char *s;
size_t len;
}s; /* string */
double n; /* number */
}u;
MJ_type type;
};
enum
{
MJ_PARSE_OK = 0,
MJ_PARSE_EXPECT_VALUE,
MJ_PARSE_INVALID_VALUE,
MJ_PARSE_ROOT_NOT_SINGULAR,
MJ_PARSE_NUMBER_TOO_BIG,
MJ_PARSE_MISS_QUOTATION_MARK,
MJ_PARSE_INVALID_STRING_ESCAPE,
MJ_PARSE_INVALID_STRING_CHAR,
MJ_PARSE_INVALID_UNICODE_HEX,
MJ_PARSE_INVALID_UNICODE_SURROGATE,
MJ_PARSE_MISS_COMMA_OR_SQUARE_BRACKET
};
#define MJ_init(v) do { (v)->type = MJ_NULL; } while(0)
int MJ_parse(MJ_value *v, const char *json);
void MJ_free(MJ_value *v);
MJ_type MJ_get_type(const MJ_value *v);
#define MJ_set_null(v) MJ_free(v)
int MJ_get_boolean(const MJ_value *v);
void MJ_set_boolean(MJ_value *v, int b);
double MJ_get_number(const MJ_value *v);
void MJ_set_number(MJ_value *v, double n);
const char* MJ_get_string(const MJ_value *v);
size_t MJ_get_string_length(const MJ_value *v);
void MJ_set_string(MJ_value *v, const char *s, size_t len);
size_t MJ_get_array_size(const MJ_value* v);
MJ_value* MJ_get_array_element(const MJ_value* v, size_t index);
#endif