-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson.h
More file actions
57 lines (44 loc) · 1.53 KB
/
json.h
File metadata and controls
57 lines (44 loc) · 1.53 KB
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
#ifndef JSON_H
#define JSON_H
#include <string.h>
#include <stdlib.h>
#ifndef __cplusplus
typedef char* string;
typedef unsigned char bool;
#define true (1)
#define false (0)
#define TRUE true
#define FALSE false
#endif
#define new(x) (x *) malloc(sizeof(x))
#define newWithSize(x, y) (x *) malloc(y * sizeof(x))
#define renewWithSize(x, y, z) (y *) realloc(x, z * sizeof(y))
#define isWhitespace(x) x == '\r' || x == '\n' || x == '\t' || x == ' '
#define removeWhitespace(x) while(isWhitespace(*x)) x++
#define removeWhitespaceCalcOffset(x, y) while(isWhitespace(*x)) { x++; y++; }
typedef char character;
struct _jsonobject;
struct _jsonpair;
union _jsonvalue;
typedef enum {
JSON_STRING = 0,
JSON_OBJECT
} JSONValueType;
typedef struct _jsonobject {
struct _jsonpair *pairs;
int count;
} JSONObject;
typedef struct _jsonpair {
string key;
union _jsonvalue *value;
JSONValueType type;
} JSONPair;
typedef union _jsonvalue {
string stringValue;
struct _jsonobject *jsonObject;
} JSONValue;
JSONObject *parseJSON(string);
void freeJSONFromMemory(JSONObject *);
static int strNextOccurence(string, char);
static JSONObject * _parseJSON(string, int *);
#endif