fjson 0.1.0 → 0.1.1
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.
- data/CHANGES +0 -3
- data/Rakefile +43 -41
- data/ext/extensions/array_ext/array_ext.c +13 -81
- data/ext/extensions/array_ext/array_ext.h +4 -8
- data/ext/extensions/array_ext/extconf.mkmf.rb +3 -0
- data/ext/extensions/enumerable/enumerable.c +70 -0
- data/ext/extensions/enumerable/enumerable.h +9 -0
- data/ext/extensions/hash_ext/extconf.mkmf.rb +3 -0
- data/ext/extensions/hash_ext/hash_ext.c +13 -81
- data/ext/extensions/hash_ext/hash_ext.h +3 -8
- data/ext/json_ext/json_ext.c +12 -13
- data/ext/json_ext/json_ext.h +2 -0
- data/ext/state_ext/state_ext.c +16 -85
- data/ext/state_ext/state_ext.h +3 -7
- data/ext/state_ext/state_lib.c +107 -0
- data/ext/state_ext/state_lib.h +15 -0
- data/hash_benchmark.rb +0 -2
- data/hash_benchmark_action_support.rb +4 -0
- data/hash_benchmark_fjson.rb +3 -0
- data/hash_benchmark_json.rb +4 -0
- data/lib/json/editor.rb +1 -1
- data/mkmf_tasks.rb +99 -0
- data/rake_helper.rb +1 -1
- data/spec/array_spec.rb +12 -2
- data/spec/false_class_spec.rb +1 -1
- data/spec/float_spec.rb +1 -1
- data/spec/hash_spec.rb +13 -0
- data/spec/integer_spec.rb +1 -1
- data/spec/mkmf_tasks_spec.rb +110 -0
- data/spec/nil_class_spec.rb +1 -1
- data/spec/object_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -0
- data/spec/spec_suite.rb +3 -8
- data/spec/state_spec.rb +10 -11
- data/spec/string_spec.rb +1 -1
- data/spec/string_when_not_supporting_unicode_and_kcode_is_not_utf8_json_spec.rb +1 -1
- data/spec/string_when_supporting_unicode_and_kcode_is_not_utf8_json_spec.rb +1 -1
- data/spec/string_with_latin1_character_set_json_spec.rb +15 -15
- data/spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb +12 -12
- data/spec/true_class_spec.rb +1 -1
- metadata +58 -53
- data/mkmf_rake_builder.rb +0 -170
- data/spec/mkmf_rake_builder_spec.rb +0 -217
- data/spec/rake_helper_spec.rb +0 -9
data/CHANGES
CHANGED
data/Rakefile
CHANGED
@@ -1,46 +1,52 @@
|
|
1
1
|
dir = File.dirname(__FILE__)
|
2
2
|
require File.expand_path("#{dir}/rake_helper")
|
3
|
-
rake_builder = MkmfRakeBuilder.new
|
4
|
-
rake_builder.project_dir = File.dirname(__FILE__)
|
5
|
-
rake_builder.rake_application = Rake.application
|
6
|
-
rake_builder.rake_tasks = Rake::Task
|
7
|
-
rake_builder.rake_file_tasks = Rake::FileTask
|
8
|
-
rake_builder.dir_class = Dir
|
9
|
-
rake_builder.file_class = File
|
10
|
-
file_extension = (RUBY_PLATFORM =~ /darwin/) ? "bundle" : "so"
|
11
|
-
rake_builder.file_extension = file_extension
|
12
|
-
fjson_extensions = rake_builder.extensions_to_build = [
|
13
|
-
[:json_ext, "json_ext"],
|
14
|
-
[:state_ext, "state_ext"],
|
15
|
-
[:object_ext, "extensions/object_ext"],
|
16
|
-
[:integer_ext, "extensions/integer_ext"],
|
17
|
-
[:float_ext, "extensions/float_ext"],
|
18
|
-
[:string_ext, "extensions/string_ext"],
|
19
|
-
[:true_class_ext, "extensions/true_class_ext"],
|
20
|
-
[:false_class_ext, "extensions/false_class_ext"],
|
21
|
-
[:nil_class_ext, "extensions/nil_class_ext"],
|
22
|
-
[:array_ext, "extensions/array_ext"],
|
23
|
-
[:hash_ext, "extensions/hash_ext"]
|
24
|
-
]
|
25
|
-
|
26
|
-
rake_builder.build_default_task
|
27
|
-
rake_builder.build_compile_task
|
28
|
-
rake_builder.build_spec_task
|
29
|
-
rake_builder.build_lib_task
|
30
|
-
rake_builder.build_extension_compile_tasks
|
31
|
-
rake_builder.build_install_task
|
32
|
-
rake_builder.build_cleanup_task
|
33
|
-
|
34
3
|
def win32?
|
35
4
|
ENV["target_platform"] == "win32"
|
36
5
|
end
|
37
6
|
|
38
|
-
|
39
|
-
|
7
|
+
desc "Compiles the library"
|
8
|
+
task(:default) {mkmf_tasks.default}
|
9
|
+
|
10
|
+
desc "Compiles the library"
|
11
|
+
task(:compile) {mkmf_tasks.compile}
|
12
|
+
|
13
|
+
desc "Compiles, installs, and runs the specs"
|
14
|
+
task(:spec) {mkmf_tasks.spec}
|
15
|
+
|
16
|
+
desc "Creates the lib directory"
|
17
|
+
task(:lib) {mkmf_tasks.lib}
|
18
|
+
|
19
|
+
desc "Installs the compiled files"
|
20
|
+
task(:install) {mkmf_tasks.install}
|
21
|
+
|
22
|
+
desc "Cleans up the build files"
|
23
|
+
task(:cleanup) {mkmf_tasks.cleanup}
|
24
|
+
|
25
|
+
def mkmf_tasks
|
26
|
+
tasks = MkmfTasks.new(self)
|
27
|
+
tasks.extconf_file_name = "extconf.mkmf.rb"
|
28
|
+
tasks.project_dir = File.dirname(__FILE__)
|
29
|
+
tasks.file_extension = (RUBY_PLATFORM =~ /darwin/) ? "bundle" : "so"
|
30
|
+
tasks.extconf_arguments = ""
|
31
|
+
# tasks.extconf_arguments = "-I /usr/local/lib/ruby-mingw32/lib/ruby/1.8/i386-mingw32" if win32?
|
32
|
+
tasks.extension_paths = [
|
33
|
+
"json_ext",
|
34
|
+
"state_ext",
|
35
|
+
"extensions/object_ext",
|
36
|
+
"extensions/integer_ext",
|
37
|
+
"extensions/float_ext",
|
38
|
+
"extensions/string_ext",
|
39
|
+
"extensions/true_class_ext",
|
40
|
+
"extensions/false_class_ext",
|
41
|
+
"extensions/nil_class_ext",
|
42
|
+
"extensions/array_ext",
|
43
|
+
"extensions/hash_ext"
|
44
|
+
]
|
45
|
+
tasks
|
40
46
|
end
|
41
47
|
|
42
48
|
PKG_NAME = "fjson"
|
43
|
-
PKG_VERSION = "0.1.
|
49
|
+
PKG_VERSION = "0.1.1"
|
44
50
|
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
|
45
51
|
PKG_FILES = FileList[
|
46
52
|
'[A-Z]*',
|
@@ -49,6 +55,7 @@ PKG_FILES = FileList[
|
|
49
55
|
'ext/**/*.{h,c,rb}',
|
50
56
|
'spec/**/*.rb'
|
51
57
|
]
|
58
|
+
PKG_FILES.include('lib/**/*.so') if win32?
|
52
59
|
|
53
60
|
spec = Gem::Specification.new do |s|
|
54
61
|
s.name = PKG_NAME
|
@@ -60,6 +67,7 @@ spec = Gem::Specification.new do |s|
|
|
60
67
|
EOF
|
61
68
|
s.test_files = Dir.glob('spec/*_spec.rb')
|
62
69
|
s.description = s.summary
|
70
|
+
s.platform = (win32?) ? Gem::Platform::WIN32 : Gem::Platform::RUBY
|
63
71
|
|
64
72
|
s.files = PKG_FILES.to_a
|
65
73
|
s.require_path = 'lib'
|
@@ -75,13 +83,7 @@ spec = Gem::Specification.new do |s|
|
|
75
83
|
s.homepage = "http://fjson.rubyforge.org"
|
76
84
|
s.rubyforge_project = "fjson"
|
77
85
|
|
78
|
-
s.extensions = ["Rakefile"]
|
79
|
-
|
80
|
-
#s.add_dependency "mkrf", ">=0.1.2"
|
81
|
-
|
82
|
-
if win32?
|
83
|
-
|
84
|
-
end
|
86
|
+
s.extensions = ["Rakefile"] unless win32?
|
85
87
|
end
|
86
88
|
|
87
89
|
Rake::GemPackageTask.new(spec) do |pkg|
|
@@ -1,74 +1,17 @@
|
|
1
1
|
#include "array_ext.h"
|
2
|
+
#include "enumerable.c"
|
2
3
|
|
3
|
-
static VALUE cArray;
|
4
4
|
static VALUE mJSON;
|
5
|
-
static VALUE cState;
|
6
5
|
static VALUE cCircularDatastructure;
|
7
6
|
|
8
7
|
void Init_array_ext() {
|
9
8
|
mJSON = rb_const_get(rb_cObject, rb_intern("JSON"));
|
10
|
-
|
11
|
-
cArray = rb_const_get(rb_cObject, rb_intern("Array"));
|
9
|
+
rb_cJsonState = rb_const_get(mJSON, rb_intern("State"));
|
12
10
|
cCircularDatastructure = rb_const_get(mJSON, rb_intern("CircularDatastructure"));
|
13
|
-
rb_define_method(
|
11
|
+
rb_define_method(rb_cArray, "to_json", (VALUE(*)(ANYARGS)) &to_json, -1);
|
14
12
|
}
|
15
13
|
|
16
|
-
/**
|
17
|
-
* Returns a JSON string containing a JSON array, that is unparsed from
|
18
|
-
* this Array instance.
|
19
|
-
* _state_ is a JSON::State object, that can also be used to configure the
|
20
|
-
* produced JSON string output further.
|
21
|
-
* _depth_ is used to find out nesting depth, to indent accordingly.
|
22
|
-
*/
|
23
|
-
static VALUE to_json(argc, argv, self)
|
24
|
-
int argc;
|
25
|
-
VALUE *argv;
|
26
|
-
VALUE self;
|
27
|
-
{
|
28
|
-
VALUE state, depth;
|
29
|
-
rb_scan_args(argc, argv, "02", &state, &depth);
|
30
|
-
if(depth == Qnil) depth = rb_int2inum(0);
|
31
|
-
|
32
|
-
state = rb_funcall(cState, rb_intern("from_state"), 1, state);
|
33
|
-
return json_check_circular_and_transform(self, state, depth);
|
34
|
-
}
|
35
|
-
|
36
|
-
/** Private **/
|
37
|
-
|
38
|
-
static VALUE json_check_circular_and_transform(self, state, depth)
|
39
|
-
VALUE self, state, depth;
|
40
|
-
{
|
41
|
-
VALUE call_args = rb_ary_new3(3, self, state, depth);
|
42
|
-
return rb_ensure(json_check_circular_and_transform_call, call_args, json_check_circular_and_transform_ensure, call_args);
|
43
|
-
}
|
44
|
-
|
45
|
-
static VALUE json_check_circular_and_transform_call(args)
|
46
|
-
VALUE args;
|
47
|
-
{
|
48
|
-
VALUE self = rb_ary_entry(args, 0);
|
49
|
-
VALUE state = rb_ary_entry(args, 1);
|
50
|
-
VALUE depth = rb_ary_entry(args, 2);
|
51
|
-
if(state != Qnil) {
|
52
|
-
if(rb_funcall(state, rb_intern("seen?"), 1, self) == Qtrue) {
|
53
|
-
rb_raise(
|
54
|
-
cCircularDatastructure,
|
55
|
-
"circular data structures not supported!"
|
56
|
-
);
|
57
|
-
}
|
58
|
-
rb_funcall(state, rb_intern("remember"), 1, self);
|
59
|
-
}
|
60
|
-
return json_transform(self, state, depth);
|
61
|
-
}
|
62
|
-
|
63
|
-
static VALUE json_check_circular_and_transform_ensure(args)
|
64
|
-
VALUE args;
|
65
|
-
{
|
66
|
-
VALUE self = rb_ary_entry(args, 0);
|
67
|
-
VALUE state = rb_ary_entry(args, 1);
|
68
|
-
if(state != Qnil) {
|
69
|
-
rb_funcall(state, rb_intern("forget"), 1, self);
|
70
|
-
}
|
71
|
-
}
|
14
|
+
/** private **/
|
72
15
|
|
73
16
|
static VALUE json_transform(self, state, depth)
|
74
17
|
VALUE self, state, depth;
|
@@ -76,21 +19,21 @@ static VALUE json_transform(self, state, depth)
|
|
76
19
|
VALUE delim = rb_str_new2(",");
|
77
20
|
VALUE array_nl = Qnil;
|
78
21
|
if(state != Qnil) array_nl = rb_funcall(state, rb_intern("array_nl"), 0);
|
79
|
-
|
22
|
+
new_line(delim, array_nl);
|
80
23
|
|
81
24
|
VALUE json = rb_str_new2("[");
|
82
|
-
|
25
|
+
new_line(json, array_nl);
|
83
26
|
|
84
|
-
process_internal_json(self, json, state, depth, delim);
|
27
|
+
process_internal_json(self, json, state, depth, delim, array_nl);
|
85
28
|
|
86
|
-
|
87
|
-
|
29
|
+
new_line(json, array_nl);
|
30
|
+
if(rb_json_should_shift(state, array_nl) == Qtrue) json_shift(json, state, depth);
|
88
31
|
rb_str_cat2(json, "]");
|
89
32
|
return json;
|
90
33
|
}
|
91
34
|
|
92
|
-
static VALUE process_internal_json(self, json, state, depth, delim)
|
93
|
-
VALUE self, json, state, depth, delim;
|
35
|
+
static VALUE process_internal_json(self, json, state, depth, delim, array_nl)
|
36
|
+
VALUE self, json, state, depth, delim, array_nl;
|
94
37
|
{
|
95
38
|
VALUE next_depth = LONG2NUM(NUM2LONG(depth) + 1);
|
96
39
|
|
@@ -101,18 +44,7 @@ static VALUE process_internal_json(self, json, state, depth, delim)
|
|
101
44
|
rb_str_concat(json, delim);
|
102
45
|
}
|
103
46
|
current_value = rb_ary_entry(self, i);
|
104
|
-
|
105
|
-
rb_str_append(json,
|
47
|
+
if(rb_json_should_shift(state, array_nl) == Qtrue) json_shift(json, state, depth);
|
48
|
+
rb_str_append(json, rb_to_json(current_value, state, depth));
|
106
49
|
}
|
107
50
|
}
|
108
|
-
|
109
|
-
static VALUE json_shift(self, json, state, depth)
|
110
|
-
VALUE self, json, state, depth;
|
111
|
-
{
|
112
|
-
if(state == Qnil) return Qnil;
|
113
|
-
VALUE array_nl = rb_funcall(state, rb_intern("array_nl"), 0);
|
114
|
-
if(RSTRING(array_nl)->len == 0) return Qnil;
|
115
|
-
|
116
|
-
rb_json_state_indent(state, json, NUM2LONG(depth) + 1);
|
117
|
-
return Qnil;
|
118
|
-
}
|
@@ -1,12 +1,8 @@
|
|
1
1
|
#include "ruby.h"
|
2
2
|
#include <string.h>
|
3
|
-
#include "
|
4
|
-
#include "
|
3
|
+
#include "state_lib.h"
|
4
|
+
#include "enumerable.h"
|
5
5
|
|
6
|
-
static VALUE to_json(int, VALUE*, VALUE);
|
7
|
-
static VALUE json_check_circular_and_transform_call(VALUE);
|
8
|
-
static VALUE json_check_circular_and_transform_ensure(VALUE);
|
9
|
-
static VALUE json_check_circular_and_transform(VALUE, VALUE, VALUE);
|
10
6
|
static VALUE json_transform(VALUE, VALUE, VALUE);
|
11
|
-
static VALUE
|
12
|
-
static VALUE
|
7
|
+
static VALUE process_internal_json(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
|
8
|
+
static VALUE to_json(int, VALUE*, VALUE);
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#include "enumerable.h"
|
2
|
+
|
3
|
+
static VALUE cCircularDatastructure;
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Returns a JSON string for this object.
|
7
|
+
* _state_ is a JSON::State object, that can also be used to configure the
|
8
|
+
* produced JSON string output further.
|
9
|
+
* _depth_ is used to find out nesting depth, to indent accordingly.
|
10
|
+
*/
|
11
|
+
static VALUE to_json(argc, argv, self)
|
12
|
+
int argc;
|
13
|
+
VALUE *argv;
|
14
|
+
VALUE self;
|
15
|
+
{
|
16
|
+
VALUE state, depth;
|
17
|
+
rb_scan_args(argc, argv, "02", &state, &depth);
|
18
|
+
if(depth == Qnil) depth = INT2NUM(0);
|
19
|
+
|
20
|
+
state = rb_json_from_state(rb_cJsonState, state);
|
21
|
+
return json_check_circular_and_transform(self, state, depth);
|
22
|
+
}
|
23
|
+
|
24
|
+
static VALUE json_check_circular_and_transform(self, state, depth)
|
25
|
+
VALUE self, state, depth;
|
26
|
+
{
|
27
|
+
VALUE call_args = rb_ary_new3(3, self, state, depth);
|
28
|
+
return rb_ensure(json_check_circular_and_transform_call, call_args, json_check_circular_and_transform_ensure, call_args);
|
29
|
+
}
|
30
|
+
|
31
|
+
static VALUE json_check_circular_and_transform_call(args)
|
32
|
+
VALUE args;
|
33
|
+
{
|
34
|
+
VALUE self = rb_ary_entry(args, 0);
|
35
|
+
VALUE state = rb_ary_entry(args, 1);
|
36
|
+
VALUE depth = rb_ary_entry(args, 2);
|
37
|
+
if(state != Qnil) {
|
38
|
+
if(rb_json_state_seen(state, self) == Qtrue) {
|
39
|
+
rb_raise(
|
40
|
+
cCircularDatastructure,
|
41
|
+
"circular data structures not supported!"
|
42
|
+
);
|
43
|
+
}
|
44
|
+
rb_json_state_remember(state, self);
|
45
|
+
}
|
46
|
+
return json_transform(self, state, depth);
|
47
|
+
}
|
48
|
+
|
49
|
+
static VALUE json_check_circular_and_transform_ensure(args)
|
50
|
+
VALUE args;
|
51
|
+
{
|
52
|
+
VALUE self = rb_ary_entry(args, 0);
|
53
|
+
VALUE state = rb_ary_entry(args, 1);
|
54
|
+
if(state != Qnil) {
|
55
|
+
rb_json_state_forget(state, self);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
static VALUE new_line(result, object_nl)
|
60
|
+
VALUE result, object_nl;
|
61
|
+
{
|
62
|
+
if(object_nl != Qnil) rb_str_append(result, object_nl);
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE json_shift(json, state, depth)
|
66
|
+
VALUE json, state, depth;
|
67
|
+
{
|
68
|
+
rb_json_state_indent(state, json, NUM2LONG(depth) + 1);
|
69
|
+
return Qnil;
|
70
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include <string.h>
|
3
|
+
|
4
|
+
static VALUE to_json(int, VALUE*, VALUE);
|
5
|
+
static VALUE json_check_circular_and_transform(VALUE, VALUE, VALUE);
|
6
|
+
static VALUE json_check_circular_and_transform_call(VALUE);
|
7
|
+
static VALUE json_check_circular_and_transform_ensure(VALUE);
|
8
|
+
static VALUE new_line(VALUE, VALUE);
|
9
|
+
static VALUE json_shift(VALUE, VALUE, VALUE);
|
@@ -1,96 +1,39 @@
|
|
1
1
|
#include "hash_ext.h"
|
2
|
+
#include "enumerable.c"
|
2
3
|
|
3
|
-
static VALUE cHash;
|
4
4
|
static VALUE mJSON;
|
5
|
-
static VALUE cState;
|
6
5
|
static VALUE cCircularDatastructure;
|
7
6
|
|
8
7
|
void Init_hash_ext() {
|
9
8
|
mJSON = rb_const_get(rb_cObject, rb_intern("JSON"));
|
10
|
-
|
11
|
-
cHash = rb_const_get(rb_cObject, rb_intern("Hash"));
|
9
|
+
rb_cJsonState = rb_const_get(mJSON, rb_intern("State"));
|
12
10
|
cCircularDatastructure = rb_const_get(mJSON, rb_intern("CircularDatastructure"));
|
13
|
-
rb_define_method(
|
14
|
-
}
|
15
|
-
|
16
|
-
/**
|
17
|
-
* Returns a JSON string containing a JSON hash, that is unparsed from
|
18
|
-
* this Hash instance.
|
19
|
-
* _state_ is a JSON::State object, that can also be used to configure the
|
20
|
-
* produced JSON string output further.
|
21
|
-
* _depth_ is used to find out nesting depth, to indent accordingly.
|
22
|
-
*/
|
23
|
-
static VALUE to_json(argc, argv, self)
|
24
|
-
int argc;
|
25
|
-
VALUE *argv;
|
26
|
-
VALUE self;
|
27
|
-
{
|
28
|
-
VALUE state, depth;
|
29
|
-
rb_scan_args(argc, argv, "02", &state, &depth);
|
30
|
-
if(depth == Qnil) depth = INT2NUM(0);
|
31
|
-
|
32
|
-
state = rb_funcall(cState, rb_intern("from_state"), 1, state);
|
33
|
-
return json_check_circular_and_transform(self, state, depth);
|
11
|
+
rb_define_method(rb_cHash, "to_json", (VALUE(*)(ANYARGS)) &to_json, -1);
|
34
12
|
}
|
35
13
|
|
36
14
|
/** private **/
|
37
15
|
|
38
|
-
static VALUE json_check_circular_and_transform(self, state, depth)
|
39
|
-
VALUE self, state, depth;
|
40
|
-
{
|
41
|
-
VALUE call_args = rb_ary_new3(3, self, state, depth);
|
42
|
-
return rb_ensure(json_check_circular_and_transform_call, call_args, json_check_circular_and_transform_ensure, call_args);
|
43
|
-
}
|
44
|
-
|
45
|
-
static VALUE json_check_circular_and_transform_ensure(args)
|
46
|
-
VALUE args;
|
47
|
-
{
|
48
|
-
VALUE self = rb_ary_entry(args, 0);
|
49
|
-
VALUE state = rb_ary_entry(args, 1);
|
50
|
-
if(state != Qnil) {
|
51
|
-
rb_funcall(state, rb_intern("forget"), 1, self);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
static VALUE json_check_circular_and_transform_call(args)
|
56
|
-
VALUE args;
|
57
|
-
{
|
58
|
-
VALUE self = rb_ary_entry(args, 0);
|
59
|
-
VALUE state = rb_ary_entry(args, 1);
|
60
|
-
VALUE depth = rb_ary_entry(args, 2);
|
61
|
-
if(state != Qnil) {
|
62
|
-
if(rb_funcall(state, rb_intern("seen?"), 1, self) == Qtrue) {
|
63
|
-
rb_raise(
|
64
|
-
cCircularDatastructure,
|
65
|
-
"circular data structures not supported!"
|
66
|
-
);
|
67
|
-
}
|
68
|
-
rb_funcall(state, rb_intern("remember"), 1, self);
|
69
|
-
}
|
70
|
-
return json_transform(self, state, depth);
|
71
|
-
}
|
72
|
-
|
73
16
|
static VALUE json_transform(self, state, depth)
|
74
17
|
VALUE self, state, depth;
|
75
18
|
{
|
76
19
|
VALUE delim = rb_str_new2(",");
|
77
20
|
VALUE object_nl = Qnil;
|
78
21
|
if(state != Qnil) object_nl = rb_funcall(state, rb_intern("object_nl"), 0);
|
79
|
-
|
22
|
+
new_line(delim, object_nl);
|
80
23
|
|
81
24
|
VALUE result = rb_str_new2("{");
|
82
|
-
|
25
|
+
new_line(result, object_nl);
|
83
26
|
|
84
|
-
process_internal_json(self, result, state, depth, delim);
|
27
|
+
process_internal_json(self, result, state, depth, delim, object_nl);
|
85
28
|
|
86
|
-
|
87
|
-
|
29
|
+
new_line(result, object_nl);
|
30
|
+
if(rb_json_should_shift(state, object_nl) == Qtrue) json_shift(result, state, depth);
|
88
31
|
rb_str_append(result, rb_str_new2("}"));
|
89
32
|
return result;
|
90
33
|
}
|
91
34
|
|
92
|
-
static VALUE process_internal_json(self, json, state, depth, delim)
|
93
|
-
VALUE self, json, state, depth, delim;
|
35
|
+
static VALUE process_internal_json(self, json, state, depth, delim, object_nl)
|
36
|
+
VALUE self, json, state, depth, delim, object_nl;
|
94
37
|
{
|
95
38
|
// TODO: Use st_foreach for even better performance
|
96
39
|
VALUE key_value_pairs = rb_funcall(self, rb_intern("to_a"), 0);
|
@@ -107,22 +50,11 @@ static VALUE process_internal_json(self, json, state, depth, delim)
|
|
107
50
|
VALUE key = rb_ary_entry(key_value, 0);
|
108
51
|
VALUE value = rb_ary_entry(key_value, 1);
|
109
52
|
|
110
|
-
|
53
|
+
if(rb_json_should_shift(state, object_nl) == Qtrue) json_shift(json, state, depth);
|
111
54
|
VALUE key_string = rb_funcall(key, rb_intern("to_s"), 0);
|
112
|
-
rb_str_append(json,
|
55
|
+
rb_str_append(json, rb_to_json(key_string, state, new_depth));
|
113
56
|
rb_str_cat2(json, ":");
|
114
57
|
rb_str_append(json, space);
|
115
|
-
rb_str_append(json,
|
58
|
+
rb_str_append(json, rb_to_json(value, state, new_depth));
|
116
59
|
}
|
117
60
|
}
|
118
|
-
|
119
|
-
static VALUE json_shift(self, json, state, depth)
|
120
|
-
VALUE self, json, state, depth;
|
121
|
-
{
|
122
|
-
if(state == Qnil) return Qnil;
|
123
|
-
VALUE object_nl = rb_funcall(state, rb_intern("object_nl"), 0);
|
124
|
-
if(RSTRING(object_nl)->len == 0) return Qnil;
|
125
|
-
|
126
|
-
rb_json_state_indent(state, json, NUM2LONG(depth) + 1);
|
127
|
-
return Qnil;
|
128
|
-
}
|