-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjzon.h
81 lines (64 loc) · 1.84 KB
/
jzon.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
#ifndef _JZON_H_
#define _JZON_H_
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct JzonKeyValuePair;
typedef struct JzonKeyValuePair JzonKeyValuePair;
typedef struct JzonValue
{
bool is_string : 1;
bool is_int : 1;
bool is_float : 1;
bool is_object : 1;
bool is_array : 1;
bool is_bool : 1;
bool is_null : 1;
unsigned size;
union
{
char* string_value;
long int int_value;
bool bool_value;
double float_value;
struct JzonKeyValuePair** object_values;
struct JzonValue** array_values;
};
} JzonValue;
struct JzonKeyValuePair {
char* key;
uint64_t key_hash;
JzonValue* value;
};
typedef struct JzonParseResult {
bool success;
const char* error;
int error_pos;
JzonValue* output;
} JzonParseResult;
typedef void* (*jzon_allocate)(size_t);
typedef void (*jzon_deallocate)(void*);
typedef struct JzonAllocator {
jzon_allocate allocate;
jzon_deallocate deallocate;
} JzonAllocator;
// Parse using default malloc allocator.
JzonParseResult jzon_parse(const char* input);
// Parse using custom allocator. Make sure to call jzon_free_custom_allocator using the same allocator.
JzonParseResult jzon_parse_custom_allocator(const char* input, JzonAllocator* allocator);
// Free parse result data structure using default free deallocator.
void jzon_free(JzonValue* value);
// Free parse result data structure which was parsed using custom allocator. Make sure to pass the same allocator you did to jzon_parse_custom_allocator.
void jzon_free_custom_allocator(JzonValue* value, JzonAllocator* allocator);
// Find object value by key. Returns NULL if object is not an actual jzon object or there exists no value with the specified key. Uses a binary search algorithm.
JzonValue* jzon_get(JzonValue* object, const char* key);
#ifdef __cplusplus
}
#endif
#endif