rapidjson 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +20 -0
- data/ext/rapidjson/buffer.hh +66 -0
- data/ext/rapidjson/cext.cc +77 -0
- data/ext/rapidjson/cext.hh +20 -0
- data/ext/rapidjson/encoder.hh +150 -0
- data/ext/rapidjson/extconf.rb +19 -0
- data/ext/rapidjson/parser.hh +149 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/allocators.h +692 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/document.h +3027 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/encodedstream.h +299 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/encodings.h +716 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/error/en.h +122 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/error/error.h +216 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/filereadstream.h +99 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/filewritestream.h +104 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/fwd.h +151 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/biginteger.h +297 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/clzll.h +71 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/diyfp.h +261 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/dtoa.h +249 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/itoa.h +308 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/meta.h +186 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/pow10.h +55 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/regex.h +739 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/stack.h +232 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/strfunc.h +83 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/strtod.h +293 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/internal/swap.h +46 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/istreamwrapper.h +128 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/memorybuffer.h +70 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/memorystream.h +71 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/pointer.h +1482 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/prettywriter.h +277 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/rapidjson.h +741 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/reader.h +2246 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/schema.h +2795 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/stream.h +223 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/stringbuffer.h +121 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/uri.h +481 -0
- data/ext/rapidjson/rapidjson/include/rapidjson/writer.h +710 -0
- data/lib/rapidjson/json_gem.rb +36 -0
- data/lib/rapidjson/version.rb +5 -0
- data/lib/rapidjson.rb +9 -0
- metadata +98 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "cext.hh"
|
4
|
+
|
5
|
+
#include "rapidjson/reader.h"
|
6
|
+
|
7
|
+
using namespace rapidjson;
|
8
|
+
|
9
|
+
class NullHandler : public BaseReaderHandler<UTF8<>, NullHandler> {
|
10
|
+
static const int MAX_DEPTH = 256;
|
11
|
+
int depth = 0;
|
12
|
+
bool push() {
|
13
|
+
return depth++ < MAX_DEPTH;
|
14
|
+
}
|
15
|
+
bool pop() {
|
16
|
+
return depth-- > 0;
|
17
|
+
}
|
18
|
+
public:
|
19
|
+
bool StartObject() { return push(); }
|
20
|
+
bool EndObject(SizeType s) { return pop(); }
|
21
|
+
bool StartArray() { return push(); }
|
22
|
+
bool EndArray(SizeType s) { return pop(); }
|
23
|
+
};
|
24
|
+
|
25
|
+
struct RubyObjectHandler : public BaseReaderHandler<UTF8<>, RubyObjectHandler> {
|
26
|
+
bool Null() {
|
27
|
+
return PutValue(Qnil);
|
28
|
+
}
|
29
|
+
|
30
|
+
bool Bool(bool b) {
|
31
|
+
return PutValue(b ? Qtrue : Qfalse);
|
32
|
+
}
|
33
|
+
|
34
|
+
bool Int(int i) {
|
35
|
+
return PutValue(INT2FIX(i));
|
36
|
+
}
|
37
|
+
|
38
|
+
bool Uint(unsigned u) {
|
39
|
+
return PutValue(INT2FIX(u));
|
40
|
+
}
|
41
|
+
|
42
|
+
bool Int64(int64_t i) {
|
43
|
+
return PutValue(RB_LONG2NUM(i));
|
44
|
+
}
|
45
|
+
|
46
|
+
bool Uint64(uint64_t u) {
|
47
|
+
return PutValue(RB_ULONG2NUM(u));
|
48
|
+
}
|
49
|
+
|
50
|
+
bool Double(double d) {
|
51
|
+
return PutValue(rb_float_new(d));
|
52
|
+
}
|
53
|
+
|
54
|
+
bool String(const char* str, SizeType length, bool copy) {
|
55
|
+
VALUE string = rb_enc_str_new(str, length, rb_utf8_encoding());
|
56
|
+
return PutValue(string);
|
57
|
+
}
|
58
|
+
|
59
|
+
bool StartObject() {
|
60
|
+
return push(rb_hash_new());
|
61
|
+
}
|
62
|
+
|
63
|
+
bool Key(const char* str, SizeType length, bool copy) {
|
64
|
+
#ifdef HAVE_RB_INTERNED_STR
|
65
|
+
VALUE val = rb_enc_interned_str(str, length, rb_utf8_encoding());
|
66
|
+
#else
|
67
|
+
VALUE val = rb_str_new(str, length);
|
68
|
+
#endif
|
69
|
+
return PutKey(val);
|
70
|
+
}
|
71
|
+
|
72
|
+
bool EndObject(SizeType memberCount) {
|
73
|
+
return PutValue(pop());
|
74
|
+
}
|
75
|
+
|
76
|
+
bool StartArray() {
|
77
|
+
VALUE array = rb_ary_new();
|
78
|
+
return push(array);
|
79
|
+
}
|
80
|
+
|
81
|
+
bool EndArray(SizeType elementCount) {
|
82
|
+
VALUE val = pop();
|
83
|
+
PutValue(val);
|
84
|
+
return true;
|
85
|
+
}
|
86
|
+
|
87
|
+
bool push(VALUE val) {
|
88
|
+
if (depth < MAX_DEPTH) {
|
89
|
+
stack[depth] = val;
|
90
|
+
depth++;
|
91
|
+
return true;
|
92
|
+
} else {
|
93
|
+
rb_raise(rb_eParseError, "JSON parse error: input too deep");
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
VALUE pop() {
|
99
|
+
if (depth > 0) {
|
100
|
+
return stack[--depth];
|
101
|
+
} else {
|
102
|
+
rb_bug("rapidjson: tried to pop an empty stack");
|
103
|
+
return Qundef;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
bool PutKey(VALUE key) {
|
108
|
+
if (depth > 0) {
|
109
|
+
last_key[depth - 1] = key;
|
110
|
+
return true;
|
111
|
+
} else {
|
112
|
+
rb_bug("rapidjson: key at depth 0");
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
bool PutValue(VALUE val) {
|
118
|
+
if (depth == 0) {
|
119
|
+
stack[0] = val;
|
120
|
+
} else {
|
121
|
+
VALUE top_val = stack[depth - 1];
|
122
|
+
if (RB_TYPE_P(top_val, T_ARRAY)) {
|
123
|
+
rb_ary_push(top_val, val);
|
124
|
+
} else if (RB_TYPE_P(top_val, T_HASH)) {
|
125
|
+
rb_hash_aset(top_val, last_key[depth - 1], val);
|
126
|
+
} else {
|
127
|
+
rb_bug("rapidjson: bad type on stack");
|
128
|
+
}
|
129
|
+
}
|
130
|
+
return true;
|
131
|
+
}
|
132
|
+
|
133
|
+
VALUE GetRoot() {
|
134
|
+
VALUE val = stack[0];
|
135
|
+
if (depth != 0 || val == Qundef) {
|
136
|
+
rb_bug("rapidjson: bad root on stack");
|
137
|
+
}
|
138
|
+
return stack[0];
|
139
|
+
}
|
140
|
+
|
141
|
+
RubyObjectHandler(): depth(0) {
|
142
|
+
stack[0] = Qundef;
|
143
|
+
}
|
144
|
+
|
145
|
+
static const int MAX_DEPTH = 256;
|
146
|
+
int depth;
|
147
|
+
VALUE stack[MAX_DEPTH];
|
148
|
+
VALUE last_key[MAX_DEPTH];
|
149
|
+
};
|