oj 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +17 -23
- data/README.md +74 -425
- data/ext/oj/buf.h +103 -0
- data/ext/oj/cache8.c +4 -0
- data/ext/oj/circarray.c +68 -0
- data/ext/oj/circarray.h +23 -0
- data/ext/oj/code.c +227 -0
- data/ext/oj/code.h +40 -0
- data/ext/oj/compat.c +243 -0
- data/ext/oj/custom.c +1097 -0
- data/ext/oj/dump.c +766 -1534
- data/ext/oj/dump.h +92 -0
- data/ext/oj/dump_compat.c +937 -0
- data/ext/oj/dump_leaf.c +254 -0
- data/ext/oj/dump_object.c +810 -0
- data/ext/oj/dump_rails.c +329 -0
- data/ext/oj/dump_strict.c +416 -0
- data/ext/oj/encode.h +51 -0
- data/ext/oj/err.c +57 -0
- data/ext/oj/err.h +70 -0
- data/ext/oj/extconf.rb +17 -7
- data/ext/oj/fast.c +213 -180
- data/ext/oj/hash.c +163 -0
- data/ext/oj/hash.h +46 -0
- data/ext/oj/hash_test.c +512 -0
- data/ext/oj/mimic_json.c +817 -0
- data/ext/oj/mimic_rails.c +806 -0
- data/ext/oj/mimic_rails.h +17 -0
- data/ext/oj/object.c +752 -0
- data/ext/oj/odd.c +230 -0
- data/ext/oj/odd.h +44 -0
- data/ext/oj/oj.c +1288 -929
- data/ext/oj/oj.h +240 -69
- data/ext/oj/parse.c +1014 -0
- data/ext/oj/parse.h +92 -0
- data/ext/oj/reader.c +223 -0
- data/ext/oj/reader.h +151 -0
- data/ext/oj/resolve.c +127 -0
- data/ext/oj/{cache.h → resolve.h} +6 -13
- data/ext/oj/rxclass.c +133 -0
- data/ext/oj/rxclass.h +27 -0
- data/ext/oj/saj.c +77 -175
- data/ext/oj/scp.c +224 -0
- data/ext/oj/sparse.c +911 -0
- data/ext/oj/stream_writer.c +301 -0
- data/ext/oj/strict.c +162 -0
- data/ext/oj/string_writer.c +480 -0
- data/ext/oj/val_stack.c +98 -0
- data/ext/oj/val_stack.h +188 -0
- data/lib/oj/active_support_helper.rb +41 -0
- data/lib/oj/bag.rb +6 -10
- data/lib/oj/easy_hash.rb +52 -0
- data/lib/oj/json.rb +172 -0
- data/lib/oj/mimic.rb +260 -5
- data/lib/oj/saj.rb +13 -10
- data/lib/oj/schandler.rb +142 -0
- data/lib/oj/state.rb +131 -0
- data/lib/oj/version.rb +1 -1
- data/lib/oj.rb +11 -23
- 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 +79 -0
- data/pages/Modes.md +140 -0
- data/pages/Options.md +250 -0
- data/pages/Rails.md +60 -0
- data/pages/Security.md +20 -0
- data/test/_test_active.rb +76 -0
- data/test/_test_active_mimic.rb +96 -0
- data/test/_test_mimic_rails.rb +126 -0
- data/test/activesupport4/decoding_test.rb +105 -0
- data/test/activesupport4/encoding_test.rb +531 -0
- data/test/activesupport4/test_helper.rb +41 -0
- data/test/activesupport5/decoding_test.rb +125 -0
- data/test/activesupport5/encoding_test.rb +483 -0
- data/test/activesupport5/encoding_test_cases.rb +90 -0
- data/test/activesupport5/test_helper.rb +50 -0
- data/test/activesupport5/time_zone_test_helpers.rb +24 -0
- data/test/helper.rb +27 -0
- data/test/isolated/shared.rb +310 -0
- data/test/isolated/test_mimic_after.rb +13 -0
- data/test/isolated/test_mimic_alone.rb +12 -0
- data/test/isolated/test_mimic_as_json.rb +45 -0
- data/test/isolated/test_mimic_before.rb +13 -0
- data/test/isolated/test_mimic_define.rb +28 -0
- data/test/isolated/test_mimic_rails_after.rb +22 -0
- data/test/isolated/test_mimic_rails_before.rb +21 -0
- data/test/isolated/test_mimic_redefine.rb +15 -0
- data/test/json_gem/json_addition_test.rb +216 -0
- data/test/json_gem/json_common_interface_test.rb +143 -0
- data/test/json_gem/json_encoding_test.rb +109 -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 +383 -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 +18 -0
- data/test/perf_compat.rb +130 -0
- data/test/perf_fast.rb +9 -9
- data/test/perf_file.rb +64 -0
- data/test/{perf_obj.rb → perf_object.rb} +24 -10
- data/test/perf_scp.rb +151 -0
- data/test/perf_strict.rb +32 -113
- data/test/sample.rb +2 -3
- data/test/test_compat.rb +474 -0
- data/test/test_custom.rb +355 -0
- data/test/test_debian.rb +53 -0
- data/test/test_fast.rb +66 -16
- data/test/test_file.rb +237 -0
- data/test/test_gc.rb +49 -0
- data/test/test_hash.rb +29 -0
- data/test/test_null.rb +376 -0
- data/test/test_object.rb +1010 -0
- data/test/test_saj.rb +16 -16
- data/test/test_scp.rb +417 -0
- data/test/test_strict.rb +410 -0
- data/test/test_various.rb +815 -0
- data/test/test_writer.rb +308 -0
- data/test/tests.rb +9 -902
- data/test/tests_mimic.rb +14 -0
- data/test/tests_mimic_addition.rb +7 -0
- metadata +253 -38
- data/ext/oj/cache.c +0 -148
- data/ext/oj/foo.rb +0 -6
- data/ext/oj/load.c +0 -1049
- data/test/a.rb +0 -38
- data/test/perf1.rb +0 -64
- data/test/perf2.rb +0 -76
- data/test/perf_obj_old.rb +0 -213
- data/test/test_mimic.rb +0 -208
data/ext/oj/dump.h
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
/* dump.h
|
2
|
+
* Copyright (c) 2011, Peter Ohler
|
3
|
+
* All rights reserved.
|
4
|
+
*/
|
5
|
+
|
6
|
+
#ifndef __OJ_DUMP_H__
|
7
|
+
#define __OJ_DUMP_H__
|
8
|
+
|
9
|
+
#include <ruby.h>
|
10
|
+
|
11
|
+
#include "oj.h"
|
12
|
+
|
13
|
+
#define MAX_DEPTH 1000
|
14
|
+
|
15
|
+
// Extra padding at end of buffer.
|
16
|
+
#define BUFFER_EXTRA 10
|
17
|
+
|
18
|
+
extern void oj_dump_nil(VALUE obj, int depth, Out out, bool as_ok);
|
19
|
+
extern void oj_dump_true(VALUE obj, int depth, Out out, bool as_ok);
|
20
|
+
extern void oj_dump_false(VALUE obj, int depth, Out out, bool as_ok);
|
21
|
+
extern void oj_dump_fixnum(VALUE obj, int depth, Out out, bool as_ok);
|
22
|
+
extern void oj_dump_bignum(VALUE obj, int depth, Out out, bool as_ok);
|
23
|
+
extern void oj_dump_float(VALUE obj, int depth, Out out, bool as_ok);
|
24
|
+
extern void oj_dump_str(VALUE obj, int depth, Out out, bool as_ok);
|
25
|
+
extern void oj_dump_sym(VALUE obj, int depth, Out out, bool as_ok);
|
26
|
+
extern void oj_dump_class(VALUE obj, int depth, Out out, bool as_ok);
|
27
|
+
|
28
|
+
extern void oj_dump_raw(const char *str, size_t cnt, Out out);
|
29
|
+
extern void oj_dump_cstr(const char *str, size_t cnt, bool is_sym, bool escape1, Out out);
|
30
|
+
extern void oj_dump_ruby_time(VALUE obj, Out out);
|
31
|
+
extern void oj_dump_xml_time(VALUE obj, Out out);
|
32
|
+
extern void oj_dump_time(VALUE obj, Out out, int withZone);
|
33
|
+
extern void oj_dump_obj_to_s(VALUE obj, Out out);
|
34
|
+
|
35
|
+
extern const char* oj_nan_str(VALUE obj, int opt, int mode, bool plus, int *lenp);
|
36
|
+
|
37
|
+
extern void oj_grow_out(Out out, size_t len);
|
38
|
+
extern long oj_check_circular(VALUE obj, Out out);
|
39
|
+
|
40
|
+
extern void oj_dump_strict_val(VALUE obj, int depth, Out out);
|
41
|
+
extern void oj_dump_null_val(VALUE obj, int depth, Out out);
|
42
|
+
extern void oj_dump_obj_val(VALUE obj, int depth, Out out);
|
43
|
+
extern void oj_dump_compat_val(VALUE obj, int depth, Out out, bool as_ok);
|
44
|
+
extern void oj_dump_rails_val(VALUE obj, int depth, Out out, bool as_ok);
|
45
|
+
extern void oj_dump_custom_val(VALUE obj, int depth, Out out, bool as_ok);
|
46
|
+
|
47
|
+
extern VALUE oj_add_to_json(int argc, VALUE *argv, VALUE self);
|
48
|
+
extern VALUE oj_remove_to_json(int argc, VALUE *argv, VALUE self);
|
49
|
+
|
50
|
+
// TBD remove when refactor complete
|
51
|
+
extern void oj_dump_comp_val(VALUE obj, int depth, Out out, int argc, VALUE *argv, bool as_ok);
|
52
|
+
|
53
|
+
|
54
|
+
inline static void
|
55
|
+
assure_size(Out out, size_t len) {
|
56
|
+
if (out->end - out->cur <= (long)len) {
|
57
|
+
oj_grow_out(out, len);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
inline static void
|
62
|
+
fill_indent(Out out, int cnt) {
|
63
|
+
if (0 < out->indent) {
|
64
|
+
cnt *= out->indent;
|
65
|
+
*out->cur++ = '\n';
|
66
|
+
for (; 0 < cnt; cnt--) {
|
67
|
+
*out->cur++ = ' ';
|
68
|
+
}
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
inline static void
|
73
|
+
dump_ulong(unsigned long num, Out out) {
|
74
|
+
char buf[32];
|
75
|
+
char *b = buf + sizeof(buf) - 1;
|
76
|
+
|
77
|
+
*b-- = '\0';
|
78
|
+
if (0 < num) {
|
79
|
+
for (; 0 < num; num /= 10, b--) {
|
80
|
+
*b = (num % 10) + '0';
|
81
|
+
}
|
82
|
+
b++;
|
83
|
+
} else {
|
84
|
+
*b = '0';
|
85
|
+
}
|
86
|
+
for (; '\0' != *b; b++) {
|
87
|
+
*out->cur++ = *b;
|
88
|
+
}
|
89
|
+
*out->cur = '\0';
|
90
|
+
}
|
91
|
+
|
92
|
+
#endif /* __OJ_DUMP_H__ */
|