oj 2.18.3 → 3.13.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1324 -0
- data/README.md +51 -204
- data/RELEASE_NOTES.md +61 -0
- data/ext/oj/buf.h +49 -72
- data/ext/oj/cache.c +326 -0
- data/ext/oj/cache.h +21 -0
- data/ext/oj/cache8.c +61 -64
- data/ext/oj/cache8.h +12 -39
- data/ext/oj/circarray.c +37 -68
- data/ext/oj/circarray.h +16 -42
- data/ext/oj/code.c +221 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +231 -107
- data/ext/oj/custom.c +1125 -0
- data/ext/oj/debug.c +132 -0
- data/ext/oj/dump.c +935 -2513
- data/ext/oj/dump.h +108 -0
- data/ext/oj/dump_compat.c +936 -0
- data/ext/oj/dump_leaf.c +164 -0
- data/ext/oj/dump_object.c +761 -0
- data/ext/oj/dump_strict.c +410 -0
- data/ext/oj/encode.h +7 -42
- data/ext/oj/encoder.c +43 -0
- data/ext/oj/err.c +40 -54
- data/ext/oj/err.h +52 -46
- data/ext/oj/extconf.rb +21 -30
- data/ext/oj/fast.c +1097 -1080
- data/ext/oj/intern.c +301 -0
- data/ext/oj/intern.h +26 -0
- data/ext/oj/mimic_json.c +893 -0
- data/ext/oj/object.c +549 -620
- data/ext/oj/odd.c +155 -167
- data/ext/oj/odd.h +37 -63
- data/ext/oj/oj.c +1661 -2063
- data/ext/oj/oj.h +341 -270
- data/ext/oj/parse.c +974 -737
- data/ext/oj/parse.h +105 -97
- data/ext/oj/parser.c +1526 -0
- data/ext/oj/parser.h +90 -0
- data/ext/oj/rails.c +1504 -0
- data/ext/oj/rails.h +18 -0
- data/ext/oj/reader.c +141 -163
- data/ext/oj/reader.h +75 -113
- data/ext/oj/resolve.c +45 -93
- data/ext/oj/resolve.h +7 -34
- data/ext/oj/rxclass.c +143 -0
- data/ext/oj/rxclass.h +26 -0
- data/ext/oj/saj.c +447 -511
- data/ext/oj/saj2.c +348 -0
- data/ext/oj/scp.c +91 -138
- data/ext/oj/sparse.c +793 -644
- data/ext/oj/stream_writer.c +331 -0
- data/ext/oj/strict.c +145 -109
- data/ext/oj/string_writer.c +493 -0
- data/ext/oj/trace.c +72 -0
- data/ext/oj/trace.h +28 -0
- data/ext/oj/usual.c +1254 -0
- data/ext/oj/util.c +136 -0
- data/ext/oj/util.h +20 -0
- data/ext/oj/val_stack.c +62 -70
- data/ext/oj/val_stack.h +95 -129
- data/ext/oj/validate.c +51 -0
- data/ext/oj/wab.c +622 -0
- data/lib/oj/bag.rb +1 -0
- data/lib/oj/easy_hash.rb +17 -8
- data/lib/oj/error.rb +10 -11
- data/lib/oj/json.rb +176 -0
- data/lib/oj/mimic.rb +158 -19
- data/lib/oj/state.rb +132 -0
- data/lib/oj/version.rb +2 -2
- data/lib/oj.rb +1 -31
- data/pages/Advanced.md +22 -0
- data/pages/Compatibility.md +25 -0
- data/pages/Custom.md +23 -0
- data/pages/Encoding.md +65 -0
- data/pages/JsonGem.md +94 -0
- data/pages/Modes.md +161 -0
- data/pages/Options.md +327 -0
- data/pages/Parser.md +309 -0
- data/pages/Rails.md +167 -0
- data/pages/Security.md +20 -0
- data/pages/WAB.md +13 -0
- data/test/activerecord/result_test.rb +32 -0
- data/test/activesupport4/decoding_test.rb +108 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/abstract_unit.rb +45 -0
- data/test/activesupport5/decoding_test.rb +133 -0
- data/test/activesupport5/encoding_test.rb +500 -0
- data/test/activesupport5/encoding_test_cases.rb +98 -0
- data/test/activesupport5/test_helper.rb +72 -0
- data/test/activesupport5/time_zone_test_helpers.rb +39 -0
- data/test/activesupport6/abstract_unit.rb +44 -0
- data/test/activesupport6/decoding_test.rb +133 -0
- data/test/activesupport6/encoding_test.rb +507 -0
- data/test/activesupport6/encoding_test_cases.rb +98 -0
- data/test/activesupport6/test_common.rb +17 -0
- data/test/activesupport6/test_helper.rb +163 -0
- data/test/activesupport6/time_zone_test_helpers.rb +39 -0
- data/test/activesupport7/abstract_unit.rb +49 -0
- data/test/activesupport7/decoding_test.rb +125 -0
- data/test/activesupport7/encoding_test.rb +486 -0
- data/test/activesupport7/encoding_test_cases.rb +104 -0
- data/test/activesupport7/time_zone_test_helpers.rb +47 -0
- data/test/bar.rb +9 -0
- data/test/baz.rb +16 -0
- data/test/bug.rb +11 -46
- data/test/foo.rb +69 -16
- data/test/helper.rb +10 -1
- data/test/isolated/shared.rb +12 -8
- data/test/isolated/test_mimic_rails_after.rb +3 -3
- data/test/isolated/test_mimic_rails_before.rb +3 -3
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +153 -0
- data/test/json_gem/json_encoding_test.rb +107 -0
- data/test/json_gem/json_ext_parser_test.rb +20 -0
- data/test/json_gem/json_fixtures_test.rb +35 -0
- data/test/json_gem/json_generator_test.rb +397 -0
- data/test/json_gem/json_generic_object_test.rb +90 -0
- data/test/json_gem/json_parser_test.rb +470 -0
- data/test/json_gem/json_string_matching_test.rb +42 -0
- data/test/json_gem/test_helper.rb +26 -0
- data/test/mem.rb +33 -0
- data/test/perf.rb +1 -1
- data/test/perf_compat.rb +30 -28
- data/test/perf_dump.rb +50 -0
- data/test/perf_object.rb +1 -1
- data/test/perf_once.rb +58 -0
- data/test/perf_parser.rb +189 -0
- data/test/perf_scp.rb +11 -10
- data/test/perf_strict.rb +30 -19
- data/test/perf_wab.rb +131 -0
- data/test/prec.rb +23 -0
- data/test/sample.rb +0 -1
- data/test/sample_json.rb +1 -1
- data/test/test_compat.rb +219 -102
- data/test/test_custom.rb +533 -0
- data/test/test_fast.rb +107 -35
- data/test/test_file.rb +19 -25
- data/test/test_generate.rb +21 -0
- data/test/test_hash.rb +11 -1
- data/test/test_integer_range.rb +72 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +357 -70
- data/test/test_parser.rb +27 -0
- data/test/test_parser_saj.rb +245 -0
- data/test/test_parser_usual.rb +217 -0
- data/test/test_rails.rb +35 -0
- data/test/test_saj.rb +1 -1
- data/test/test_scp.rb +39 -2
- data/test/test_strict.rb +186 -7
- data/test/test_various.rb +160 -774
- data/test/test_wab.rb +307 -0
- data/test/test_writer.rb +90 -2
- data/test/tests.rb +24 -0
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- data/test/zoo.rb +13 -0
- metadata +194 -56
- data/ext/oj/hash.c +0 -163
- data/ext/oj/hash.h +0 -46
- data/ext/oj/hash_test.c +0 -512
- data/test/activesupport_datetime_test.rb +0 -23
- data/test/bug2.rb +0 -10
- data/test/bug3.rb +0 -46
- data/test/bug_fast.rb +0 -32
- data/test/bug_load.rb +0 -24
- data/test/crash.rb +0 -111
- data/test/curl/curl_oj.rb +0 -46
- data/test/curl/get_oj.rb +0 -24
- data/test/curl/just_curl.rb +0 -31
- data/test/curl/just_oj.rb +0 -51
- data/test/example.rb +0 -11
- data/test/io.rb +0 -48
- data/test/isolated/test_mimic_rails_datetime.rb +0 -27
- data/test/mod.rb +0 -16
- data/test/rails.rb +0 -50
- data/test/russian.rb +0 -18
- data/test/struct.rb +0 -29
- data/test/test_serializer.rb +0 -59
- data/test/write_timebars.rb +0 -31
data/ext/oj/compat.c
CHANGED
|
@@ -1,155 +1,279 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* All rights reserved.
|
|
4
|
-
*
|
|
5
|
-
* Redistribution and use in source and binary forms, with or without
|
|
6
|
-
* modification, are permitted provided that the following conditions are met:
|
|
7
|
-
*
|
|
8
|
-
* - Redistributions of source code must retain the above copyright notice, this
|
|
9
|
-
* list of conditions and the following disclaimer.
|
|
10
|
-
*
|
|
11
|
-
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
13
|
-
* and/or other materials provided with the distribution.
|
|
14
|
-
*
|
|
15
|
-
* - Neither the name of Peter Ohler nor the names of its contributors may be
|
|
16
|
-
* used to endorse or promote products derived from this software without
|
|
17
|
-
* specific prior written permission.
|
|
18
|
-
*
|
|
19
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
29
|
-
*/
|
|
1
|
+
// Copyright (c) 2012 Peter Ohler. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License. See LICENSE file in the project root for license details.
|
|
30
3
|
|
|
31
4
|
#include <stdio.h>
|
|
32
5
|
|
|
33
|
-
#include "
|
|
6
|
+
#include "encode.h"
|
|
34
7
|
#include "err.h"
|
|
8
|
+
#include "intern.h"
|
|
9
|
+
#include "oj.h"
|
|
35
10
|
#include "parse.h"
|
|
36
11
|
#include "resolve.h"
|
|
37
|
-
#include "
|
|
38
|
-
#include "encode.h"
|
|
12
|
+
#include "trace.h"
|
|
39
13
|
|
|
40
|
-
static void
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
0 == strncmp(pi->options.create_id, key, klen)) {
|
|
52
|
-
parent->classname = oj_strndup(str, len);
|
|
53
|
-
parent->clen = len;
|
|
14
|
+
static void hash_set_cstr(ParseInfo pi, Val kval, const char *str, size_t len, const char *orig) {
|
|
15
|
+
const char * key = kval->key;
|
|
16
|
+
int klen = kval->klen;
|
|
17
|
+
Val parent = stack_peek(&pi->stack);
|
|
18
|
+
volatile VALUE rkey = kval->key_val;
|
|
19
|
+
|
|
20
|
+
if (Qundef == rkey && Yes == pi->options.create_ok && NULL != pi->options.create_id &&
|
|
21
|
+
*pi->options.create_id == *key && (int)pi->options.create_id_len == klen &&
|
|
22
|
+
0 == strncmp(pi->options.create_id, key, klen)) {
|
|
23
|
+
parent->classname = oj_strndup(str, len);
|
|
24
|
+
parent->clen = len;
|
|
54
25
|
} else {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
26
|
+
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
|
27
|
+
|
|
28
|
+
if (Qundef == rkey) {
|
|
29
|
+
if (Yes != pi->options.cache_keys) {
|
|
30
|
+
if (Yes == pi->options.sym_key) {
|
|
31
|
+
rkey = ID2SYM(rb_intern3(key, klen, oj_utf8_encoding));
|
|
32
|
+
} else {
|
|
33
|
+
rkey = rb_utf8_str_new(key, klen);
|
|
34
|
+
}
|
|
35
|
+
} else if (Yes == pi->options.sym_key) {
|
|
36
|
+
rkey = oj_sym_intern(key, klen);
|
|
37
|
+
} else {
|
|
38
|
+
rkey = oj_str_intern(key, klen);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
|
42
|
+
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
|
|
43
|
+
|
|
44
|
+
if (Qnil != clas) {
|
|
45
|
+
rstr = rb_funcall(clas, oj_json_create_id, 1, rstr);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (rb_cHash != rb_obj_class(parent->val)) {
|
|
49
|
+
// The rb_hash_set would still work but the unit tests for the
|
|
50
|
+
// json gem require the less efficient []= method be called to set
|
|
51
|
+
// values. Even using the store method to set the values will fail
|
|
52
|
+
// the unit tests.
|
|
53
|
+
rb_funcall(parent->val, rb_intern("[]="), 2, rkey, rstr);
|
|
54
|
+
} else {
|
|
55
|
+
rb_hash_aset(parent->val, rkey, rstr);
|
|
56
|
+
}
|
|
57
|
+
if (Yes == pi->options.trace) {
|
|
58
|
+
oj_trace_parse_call("set_string", pi, __FILE__, __LINE__, rstr);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static VALUE start_hash(ParseInfo pi) {
|
|
64
|
+
volatile VALUE h;
|
|
65
|
+
|
|
66
|
+
if (Qnil != pi->options.hash_class) {
|
|
67
|
+
h = rb_class_new_instance(0, NULL, pi->options.hash_class);
|
|
68
|
+
} else {
|
|
69
|
+
h = rb_hash_new();
|
|
70
|
+
}
|
|
71
|
+
if (Yes == pi->options.trace) {
|
|
72
|
+
oj_trace_parse_in("start_hash", pi, __FILE__, __LINE__);
|
|
66
73
|
}
|
|
74
|
+
return h;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
static void
|
|
70
|
-
|
|
71
|
-
Val parent = stack_peek(&pi->stack);
|
|
77
|
+
static void end_hash(struct _parseInfo *pi) {
|
|
78
|
+
Val parent = stack_peek(&pi->stack);
|
|
72
79
|
|
|
73
80
|
if (0 != parent->classname) {
|
|
74
|
-
|
|
81
|
+
volatile VALUE clas;
|
|
75
82
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
clas = oj_name2class(pi, parent->classname, parent->clen, 0, rb_eArgError);
|
|
84
|
+
if (Qundef != clas) { // else an error
|
|
85
|
+
ID creatable = rb_intern("json_creatable?");
|
|
86
|
+
|
|
87
|
+
if (!rb_respond_to(clas, creatable) || Qtrue == rb_funcall(clas, creatable, 0)) {
|
|
88
|
+
parent->val = rb_funcall(clas, oj_json_create_id, 1, parent->val);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (0 != parent->classname) {
|
|
92
|
+
xfree((char *)parent->classname);
|
|
93
|
+
parent->classname = 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (Yes == pi->options.trace) {
|
|
97
|
+
oj_trace_parse_hash_end(pi, __FILE__, __LINE__);
|
|
84
98
|
}
|
|
85
99
|
}
|
|
86
100
|
|
|
87
|
-
static
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
static void add_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
102
|
+
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
|
103
|
+
|
|
104
|
+
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
|
105
|
+
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
if (Qnil != clas) {
|
|
108
|
+
pi->stack.head->val = rb_funcall(clas, oj_json_create_id, 1, rstr);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
93
111
|
}
|
|
94
|
-
|
|
95
|
-
if (Yes == pi->options.
|
|
96
|
-
|
|
112
|
+
pi->stack.head->val = rstr;
|
|
113
|
+
if (Yes == pi->options.trace) {
|
|
114
|
+
oj_trace_parse_call("add_string", pi, __FILE__, __LINE__, rstr);
|
|
97
115
|
}
|
|
98
|
-
return rkey;
|
|
99
116
|
}
|
|
100
117
|
|
|
101
|
-
static void
|
|
102
|
-
add_num(ParseInfo pi, NumInfo ni) {
|
|
118
|
+
static void add_num(ParseInfo pi, NumInfo ni) {
|
|
103
119
|
pi->stack.head->val = oj_num_as_value(ni);
|
|
120
|
+
if (Yes == pi->options.trace) {
|
|
121
|
+
oj_trace_parse_call("add_number", pi, __FILE__, __LINE__, pi->stack.head->val);
|
|
122
|
+
}
|
|
104
123
|
}
|
|
105
124
|
|
|
106
|
-
static void
|
|
107
|
-
|
|
108
|
-
|
|
125
|
+
static void hash_set_num(struct _parseInfo *pi, Val parent, NumInfo ni) {
|
|
126
|
+
volatile VALUE rval = oj_num_as_value(ni);
|
|
127
|
+
|
|
128
|
+
if (!oj_use_hash_alt && rb_cHash != rb_obj_class(parent->val)) {
|
|
129
|
+
// The rb_hash_set would still work but the unit tests for the
|
|
130
|
+
// json gem require the less efficient []= method be called to set
|
|
131
|
+
// values. Even using the store method to set the values will fail
|
|
132
|
+
// the unit tests.
|
|
133
|
+
rb_funcall(stack_peek(&pi->stack)->val,
|
|
134
|
+
rb_intern("[]="),
|
|
135
|
+
2,
|
|
136
|
+
oj_calc_hash_key(pi, parent),
|
|
137
|
+
rval);
|
|
138
|
+
} else {
|
|
139
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), rval);
|
|
140
|
+
}
|
|
141
|
+
if (Yes == pi->options.trace) {
|
|
142
|
+
oj_trace_parse_call("set_number", pi, __FILE__, __LINE__, rval);
|
|
143
|
+
}
|
|
109
144
|
}
|
|
110
145
|
|
|
111
|
-
static void
|
|
112
|
-
|
|
113
|
-
|
|
146
|
+
static void hash_set_value(ParseInfo pi, Val parent, VALUE value) {
|
|
147
|
+
if (rb_cHash != rb_obj_class(parent->val)) {
|
|
148
|
+
// The rb_hash_set would still work but the unit tests for the
|
|
149
|
+
// json gem require the less efficient []= method be called to set
|
|
150
|
+
// values. Even using the store method to set the values will fail
|
|
151
|
+
// the unit tests.
|
|
152
|
+
rb_funcall(stack_peek(&pi->stack)->val,
|
|
153
|
+
rb_intern("[]="),
|
|
154
|
+
2,
|
|
155
|
+
oj_calc_hash_key(pi, parent),
|
|
156
|
+
value);
|
|
157
|
+
} else {
|
|
158
|
+
rb_hash_aset(stack_peek(&pi->stack)->val, oj_calc_hash_key(pi, parent), value);
|
|
159
|
+
}
|
|
160
|
+
if (Yes == pi->options.trace) {
|
|
161
|
+
oj_trace_parse_call("set_value", pi, __FILE__, __LINE__, value);
|
|
162
|
+
}
|
|
114
163
|
}
|
|
115
164
|
|
|
165
|
+
static VALUE start_array(ParseInfo pi) {
|
|
166
|
+
if (Qnil != pi->options.array_class) {
|
|
167
|
+
return rb_class_new_instance(0, NULL, pi->options.array_class);
|
|
168
|
+
}
|
|
169
|
+
if (Yes == pi->options.trace) {
|
|
170
|
+
oj_trace_parse_in("start_array", pi, __FILE__, __LINE__);
|
|
171
|
+
}
|
|
172
|
+
return rb_ary_new();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static void array_append_num(ParseInfo pi, NumInfo ni) {
|
|
176
|
+
Val parent = stack_peek(&pi->stack);
|
|
177
|
+
volatile VALUE rval = oj_num_as_value(ni);
|
|
178
|
+
|
|
179
|
+
if (!oj_use_array_alt && rb_cArray != rb_obj_class(parent->val)) {
|
|
180
|
+
// The rb_ary_push would still work but the unit tests for the json
|
|
181
|
+
// gem require the less efficient << method be called to push the
|
|
182
|
+
// values.
|
|
183
|
+
rb_funcall(parent->val, rb_intern("<<"), 1, rval);
|
|
184
|
+
} else {
|
|
185
|
+
rb_ary_push(parent->val, rval);
|
|
186
|
+
}
|
|
187
|
+
if (Yes == pi->options.trace) {
|
|
188
|
+
oj_trace_parse_call("append_number", pi, __FILE__, __LINE__, rval);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static void array_append_cstr(ParseInfo pi, const char *str, size_t len, const char *orig) {
|
|
193
|
+
volatile VALUE rstr = oj_cstr_to_value(str, len, (size_t)pi->options.cache_str);
|
|
194
|
+
|
|
195
|
+
if (Yes == pi->options.create_ok && NULL != pi->options.str_rx.head) {
|
|
196
|
+
VALUE clas = oj_rxclass_match(&pi->options.str_rx, str, (int)len);
|
|
197
|
+
|
|
198
|
+
if (Qnil != clas) {
|
|
199
|
+
rb_ary_push(stack_peek(&pi->stack)->val, rb_funcall(clas, oj_json_create_id, 1, rstr));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
rb_ary_push(stack_peek(&pi->stack)->val, rstr);
|
|
204
|
+
if (Yes == pi->options.trace) {
|
|
205
|
+
oj_trace_parse_call("append_string", pi, __FILE__, __LINE__, rstr);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
116
208
|
|
|
117
|
-
void
|
|
118
|
-
oj_set_compat_callbacks(ParseInfo pi) {
|
|
209
|
+
void oj_set_compat_callbacks(ParseInfo pi) {
|
|
119
210
|
oj_set_strict_callbacks(pi);
|
|
120
|
-
pi->
|
|
121
|
-
pi->
|
|
122
|
-
pi->
|
|
123
|
-
pi->hash_set_num
|
|
124
|
-
pi->
|
|
211
|
+
pi->start_hash = start_hash;
|
|
212
|
+
pi->end_hash = end_hash;
|
|
213
|
+
pi->hash_set_cstr = hash_set_cstr;
|
|
214
|
+
pi->hash_set_num = hash_set_num;
|
|
215
|
+
pi->hash_set_value = hash_set_value;
|
|
216
|
+
pi->add_num = add_num;
|
|
217
|
+
pi->add_cstr = add_cstr;
|
|
218
|
+
pi->array_append_cstr = array_append_cstr;
|
|
219
|
+
pi->start_array = start_array;
|
|
220
|
+
pi->array_append_num = array_append_num;
|
|
125
221
|
}
|
|
126
222
|
|
|
127
223
|
VALUE
|
|
128
224
|
oj_compat_parse(int argc, VALUE *argv, VALUE self) {
|
|
129
|
-
struct
|
|
225
|
+
struct _parseInfo pi;
|
|
226
|
+
|
|
227
|
+
parse_info_init(&pi);
|
|
228
|
+
pi.options = oj_default_options;
|
|
229
|
+
pi.handler = Qnil;
|
|
230
|
+
pi.err_class = Qnil;
|
|
231
|
+
pi.max_depth = 0;
|
|
232
|
+
pi.options.allow_nan = Yes;
|
|
233
|
+
pi.options.nilnil = Yes;
|
|
234
|
+
pi.options.empty_string = No;
|
|
235
|
+
oj_set_compat_callbacks(&pi);
|
|
236
|
+
|
|
237
|
+
if (T_STRING == rb_type(*argv)) {
|
|
238
|
+
return oj_pi_parse(argc, argv, &pi, 0, 0, false);
|
|
239
|
+
} else {
|
|
240
|
+
return oj_pi_sparse(argc, argv, &pi, 0);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
130
243
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
244
|
+
VALUE
|
|
245
|
+
oj_compat_load(int argc, VALUE *argv, VALUE self) {
|
|
246
|
+
struct _parseInfo pi;
|
|
247
|
+
|
|
248
|
+
parse_info_init(&pi);
|
|
249
|
+
pi.options = oj_default_options;
|
|
250
|
+
pi.handler = Qnil;
|
|
251
|
+
pi.err_class = Qnil;
|
|
252
|
+
pi.max_depth = 0;
|
|
253
|
+
pi.options.allow_nan = Yes;
|
|
254
|
+
pi.options.nilnil = Yes;
|
|
255
|
+
pi.options.empty_string = Yes;
|
|
134
256
|
oj_set_compat_callbacks(&pi);
|
|
135
257
|
|
|
136
258
|
if (T_STRING == rb_type(*argv)) {
|
|
137
|
-
|
|
259
|
+
return oj_pi_parse(argc, argv, &pi, 0, 0, false);
|
|
138
260
|
} else {
|
|
139
|
-
|
|
261
|
+
return oj_pi_sparse(argc, argv, &pi, 0);
|
|
140
262
|
}
|
|
141
263
|
}
|
|
142
264
|
|
|
143
265
|
VALUE
|
|
144
266
|
oj_compat_parse_cstr(int argc, VALUE *argv, char *json, size_t len) {
|
|
145
|
-
struct
|
|
267
|
+
struct _parseInfo pi;
|
|
146
268
|
|
|
147
|
-
pi
|
|
148
|
-
pi.
|
|
149
|
-
pi.
|
|
150
|
-
|
|
151
|
-
pi.
|
|
152
|
-
pi.
|
|
269
|
+
parse_info_init(&pi);
|
|
270
|
+
pi.options = oj_default_options;
|
|
271
|
+
pi.handler = Qnil;
|
|
272
|
+
pi.err_class = Qnil;
|
|
273
|
+
pi.max_depth = 0;
|
|
274
|
+
pi.options.allow_nan = Yes;
|
|
275
|
+
pi.options.nilnil = Yes;
|
|
276
|
+
oj_set_compat_callbacks(&pi);
|
|
153
277
|
|
|
154
|
-
return oj_pi_parse(argc, argv, &pi, json, len,
|
|
278
|
+
return oj_pi_parse(argc, argv, &pi, json, len, false);
|
|
155
279
|
}
|