-
Notifications
You must be signed in to change notification settings - Fork 26
/
jute.h
58 lines (53 loc) · 1.59 KB
/
jute.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
#ifndef __JUTE_H__
#define __JUTE_H__
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <fstream>
#include <cstring>
namespace jute {
enum jType {JSTRING, JOBJECT, JARRAY, JBOOLEAN, JNUMBER, JNULL, JUNKNOWN};
class jValue {
private:
std::string makesp(int);
std::string svalue;
jType type;
std::vector<std::pair<std::string, jValue> > properties;
std::map<std::string, size_t> mpindex;
std::vector<jValue> arr;
std::string to_string_d(int);
public:
jValue();
jValue(jType);
std::string to_string();
jType get_type();
void set_type(jType);
void add_property(std::string key, jValue v);
void add_element(jValue v);
void set_string(std::string s);
int as_int();
double as_double();
bool as_bool();
void* as_null();
std::string as_string();
int size();
jValue operator[](int i);
jValue operator[](std::string s);
};
class parser {
private:
enum token_type {UNKNOWN, STRING, NUMBER, CROUSH_OPEN, CROUSH_CLOSE, BRACKET_OPEN, BRACKET_CLOSE, COMMA, COLON, BOOLEAN, NUL};
struct token;
static bool is_whitespace(const char c);
static int next_whitespace(const std::string& source, int i);
static int skip_whitespaces(const std::string& source, int i);
static std::vector<token> tokenize(std::string source);
static jValue json_parse(std::vector<token> v, int i, int& r);
public:
static jValue parse(const std::string& str);
static jValue parse_file(const std::string& str);
};
}
#endif