json-maglev- 1.6.1 → 1.6.3
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/.gitignore +8 -0
- data/.travis.yml +15 -0
- data/CHANGES +13 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/benchmarks/data/.keep +0 -0
- data/benchmarks/data-p4-3GHz-ruby18/.keep +0 -0
- data/benchmarks/generator2_benchmark.rb +1 -1
- data/benchmarks/generator_benchmark.rb +1 -1
- data/benchmarks/parser2_benchmark.rb +1 -1
- data/benchmarks/parser_benchmark.rb +1 -1
- data/diagrams/.keep +0 -0
- data/ext/json/ext/fbuffer/fbuffer.h +156 -0
- data/ext/json/ext/generator/generator.c +57 -132
- data/ext/json/ext/generator/generator.h +2 -39
- data/ext/json/ext/parser/parser.c +100 -94
- data/ext/json/ext/parser/parser.h +1 -6
- data/ext/json/ext/parser/parser.rl +18 -9
- data/java/src/json/ext/GeneratorState.java +21 -0
- data/json.gemspec +16 -16
- data/json_pure.gemspec +15 -15
- data/lib/json/add/bigdecimal.rb +21 -0
- data/lib/json/add/ostruct.rb +31 -0
- data/lib/json/add/time.rb +2 -2
- data/lib/json/common.rb +40 -5
- data/lib/json/ext/.keep +0 -0
- data/lib/json/ext.rb +6 -0
- data/lib/json/pure/generator.rb +20 -9
- data/lib/json/pure/parser.rb +7 -2
- data/lib/json/pure.rb +6 -0
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +17 -1
- data/tests/test_json_addition.rb +15 -1
- data/tests/test_json_generate.rb +66 -30
- metadata +128 -119
@@ -7,12 +7,6 @@
|
|
7
7
|
#include "re.h"
|
8
8
|
#endif
|
9
9
|
|
10
|
-
#ifdef HAVE_RUBY_ENCODING_H
|
11
|
-
#include "ruby/encoding.h"
|
12
|
-
#define FORCE_UTF8(obj) ((obj) = rb_enc_associate(rb_str_dup(obj), rb_utf8_encoding()))
|
13
|
-
#else
|
14
|
-
#define FORCE_UTF8(obj)
|
15
|
-
#endif
|
16
10
|
#ifdef HAVE_RUBY_ST_H
|
17
11
|
#include "ruby/st.h"
|
18
12
|
#else
|
@@ -50,6 +44,7 @@ typedef struct JSON_ParserStruct {
|
|
50
44
|
VALUE array_class;
|
51
45
|
int create_additions;
|
52
46
|
VALUE match_string;
|
47
|
+
FBuffer *fbuffer;
|
53
48
|
} JSON_Parser;
|
54
49
|
|
55
50
|
#define GET_PARSER \
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#include "../fbuffer/fbuffer.h"
|
1
2
|
#include "parser.h"
|
2
3
|
|
3
4
|
/* unicode */
|
@@ -298,7 +299,10 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
298
299
|
|
299
300
|
if (cs >= JSON_integer_first_final) {
|
300
301
|
long len = p - json->memo;
|
301
|
-
|
302
|
+
fbuffer_clear(json->fbuffer);
|
303
|
+
fbuffer_append(json->fbuffer, json->memo, len);
|
304
|
+
fbuffer_append_char(json->fbuffer, '\0');
|
305
|
+
*result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10);
|
302
306
|
return p + 1;
|
303
307
|
} else {
|
304
308
|
return NULL;
|
@@ -329,7 +333,10 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
329
333
|
|
330
334
|
if (cs >= JSON_float_first_final) {
|
331
335
|
long len = p - json->memo;
|
332
|
-
|
336
|
+
fbuffer_clear(json->fbuffer);
|
337
|
+
fbuffer_append(json->fbuffer, json->memo, len);
|
338
|
+
fbuffer_append_char(json->fbuffer, '\0');
|
339
|
+
*result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1));
|
333
340
|
return p + 1;
|
334
341
|
} else {
|
335
342
|
return NULL;
|
@@ -698,6 +705,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
698
705
|
json->object_class = Qnil;
|
699
706
|
json->array_class = Qnil;
|
700
707
|
}
|
708
|
+
source = rb_convert_type(source, T_STRING, "String", "to_str");
|
701
709
|
if (!json->quirks_mode) {
|
702
710
|
source = convert_encoding(StringValue(source));
|
703
711
|
}
|
@@ -815,13 +823,13 @@ static JSON_Parser *JSON_allocate()
|
|
815
823
|
{
|
816
824
|
JSON_Parser *json = ALLOC(JSON_Parser);
|
817
825
|
MEMZERO(json, JSON_Parser, 1);
|
818
|
-
json->dwrapped_parser =
|
819
|
-
json->Vsource =
|
820
|
-
json->create_id =
|
821
|
-
json->object_class =
|
822
|
-
json->array_class =
|
823
|
-
json->match_string =
|
824
|
-
|
826
|
+
json->dwrapped_parser = Qfalse;
|
827
|
+
json->Vsource = Qfalse;
|
828
|
+
json->create_id = Qfalse;
|
829
|
+
json->object_class = Qfalse;
|
830
|
+
json->array_class = Qfalse;
|
831
|
+
json->match_string = Qfalse;
|
832
|
+
json->fbuffer = fbuffer_alloc(0);
|
825
833
|
return json;
|
826
834
|
}
|
827
835
|
|
@@ -836,6 +844,7 @@ static void JSON_mark(JSON_Parser *json)
|
|
836
844
|
|
837
845
|
static void JSON_free(JSON_Parser *json)
|
838
846
|
{
|
847
|
+
fbuffer_free(json->fbuffer);
|
839
848
|
ruby_xfree(json);
|
840
849
|
}
|
841
850
|
|
@@ -83,6 +83,12 @@ public class GeneratorState extends RubyObject {
|
|
83
83
|
*/
|
84
84
|
private boolean quirksMode = DEFAULT_QUIRKS_MODE;
|
85
85
|
static final boolean DEFAULT_QUIRKS_MODE = false;
|
86
|
+
/**
|
87
|
+
* The initial buffer length of this state. (This isn't really used on all
|
88
|
+
* non-C implementations.)
|
89
|
+
*/
|
90
|
+
private int bufferInitialLength = DEFAULT_BUFFER_INITIAL_LENGTH;
|
91
|
+
static final int DEFAULT_BUFFER_INITIAL_LENGTH = 1024;
|
86
92
|
|
87
93
|
/**
|
88
94
|
* The current depth (inside a #to_json call)
|
@@ -189,6 +195,7 @@ public class GeneratorState extends RubyObject {
|
|
189
195
|
this.allowNaN = orig.allowNaN;
|
190
196
|
this.asciiOnly = orig.asciiOnly;
|
191
197
|
this.quirksMode = orig.quirksMode;
|
198
|
+
this.bufferInitialLength = orig.bufferInitialLength;
|
192
199
|
this.depth = orig.depth;
|
193
200
|
return this;
|
194
201
|
}
|
@@ -385,6 +392,18 @@ public class GeneratorState extends RubyObject {
|
|
385
392
|
return quirks_mode.getRuntime().newBoolean(quirksMode);
|
386
393
|
}
|
387
394
|
|
395
|
+
@JRubyMethod(name="buffer_initial_length")
|
396
|
+
public RubyInteger buffer_initial_length_get(ThreadContext context) {
|
397
|
+
return context.getRuntime().newFixnum(bufferInitialLength);
|
398
|
+
}
|
399
|
+
|
400
|
+
@JRubyMethod(name="buffer_initial_length=")
|
401
|
+
public IRubyObject buffer_initial_length_set(IRubyObject buffer_initial_length) {
|
402
|
+
int newLength = RubyNumeric.fix2int(buffer_initial_length);
|
403
|
+
if (newLength > 0) bufferInitialLength = newLength;
|
404
|
+
return buffer_initial_length;
|
405
|
+
}
|
406
|
+
|
388
407
|
@JRubyMethod(name="quirks_mode?")
|
389
408
|
public RubyBoolean quirks_mode_p(ThreadContext context) {
|
390
409
|
return context.getRuntime().newBoolean(quirksMode);
|
@@ -445,6 +464,7 @@ public class GeneratorState extends RubyObject {
|
|
445
464
|
allowNaN = opts.getBool("allow_nan", DEFAULT_ALLOW_NAN);
|
446
465
|
asciiOnly = opts.getBool("ascii_only", DEFAULT_ASCII_ONLY);
|
447
466
|
quirksMode = opts.getBool("quirks_mode", DEFAULT_QUIRKS_MODE);
|
467
|
+
bufferInitialLength = opts.getInt("buffer_initial_length", DEFAULT_BUFFER_INITIAL_LENGTH);
|
448
468
|
|
449
469
|
depth = opts.getInt("depth", 0);
|
450
470
|
|
@@ -473,6 +493,7 @@ public class GeneratorState extends RubyObject {
|
|
473
493
|
result.op_aset(context, runtime.newSymbol("quirks_mode"), quirks_mode_p(context));
|
474
494
|
result.op_aset(context, runtime.newSymbol("max_nesting"), max_nesting_get(context));
|
475
495
|
result.op_aset(context, runtime.newSymbol("depth"), depth_get(context));
|
496
|
+
result.op_aset(context, runtime.newSymbol("buffer_initial_length"), buffer_initial_length_get(context));
|
476
497
|
return result;
|
477
498
|
}
|
478
499
|
|
data/json.gemspec
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.6.
|
4
|
+
s.name = "json-maglev-"
|
5
|
+
s.version = "1.6.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extensions = [
|
13
|
-
s.extra_rdoc_files = [
|
14
|
-
s.files = [
|
15
|
-
s.homepage =
|
16
|
-
s.rdoc_options = [
|
17
|
-
s.require_paths = [
|
18
|
-
s.rubyforge_project =
|
19
|
-
s.rubygems_version =
|
20
|
-
s.summary =
|
21
|
-
s.test_files = [
|
8
|
+
s.authors = ["Florian Frank"]
|
9
|
+
s.date = "2011-12-01"
|
10
|
+
s.description = "This is a JSON implementation as a Ruby extension in C."
|
11
|
+
s.email = "flori@ping.de"
|
12
|
+
s.extensions = ["ext/json/ext/parser/extconf.rb", "ext/json/ext/generator/extconf.rb"]
|
13
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
14
|
+
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "benchmarks/data-p4-3GHz-ruby18/.keep", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log", "benchmarks/data/.keep", "benchmarks/generator2_benchmark.rb", "benchmarks/generator_benchmark.rb", "benchmarks/ohai.json", "benchmarks/ohai.ruby", "benchmarks/parser2_benchmark.rb", "benchmarks/parser_benchmark.rb", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "install.rb", "java/lib/bytelist-1.0.6.jar", "java/lib/jcodings.jar", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail1.json", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
15
|
+
s.homepage = "http://flori.github.com/json"
|
16
|
+
s.rdoc_options = ["--title", "JSON implemention for Ruby", "--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["ext/json/ext", "ext", "lib"]
|
18
|
+
s.rubyforge_project = "json"
|
19
|
+
s.rubygems_version = "1.8.11"
|
20
|
+
s.summary = "JSON Implementation for Ruby"
|
21
|
+
s.test_files = ["./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 3
|
data/json_pure.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.6.
|
4
|
+
s.name = "json_pure"
|
5
|
+
s.version = "1.6.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
s.files = [
|
14
|
-
s.homepage =
|
15
|
-
s.rdoc_options = [
|
16
|
-
s.require_paths = [
|
17
|
-
s.rubyforge_project =
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
20
|
-
s.test_files = [
|
8
|
+
s.authors = ["Florian Frank"]
|
9
|
+
s.date = "2011-12-01"
|
10
|
+
s.description = "This is a JSON implementation in pure Ruby."
|
11
|
+
s.email = "flori@ping.de"
|
12
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
13
|
+
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "VERSION", "benchmarks/data-p4-3GHz-ruby18/.keep", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log", "benchmarks/data/.keep", "benchmarks/generator2_benchmark.rb", "benchmarks/generator_benchmark.rb", "benchmarks/ohai.json", "benchmarks/ohai.ruby", "benchmarks/parser2_benchmark.rb", "benchmarks/parser_benchmark.rb", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "install.rb", "java/lib/bytelist-1.0.6.jar", "java/lib/jcodings.jar", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "tests/fixtures/fail1.json", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
14
|
+
s.homepage = "http://flori.github.com/json"
|
15
|
+
s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = "json"
|
18
|
+
s.rubygems_version = "1.8.11"
|
19
|
+
s.summary = "JSON Implementation for Ruby"
|
20
|
+
s.test_files = ["./tests/test_json_string_matching.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_unicode.rb", "./tests/test_json_addition.rb", "./tests/test_json_generate.rb", "./tests/test_json_encoding.rb", "./tests/test_json.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
@@ -0,0 +1,21 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
defined?(::BigDecimal) or require 'bigdecimal'
|
5
|
+
|
6
|
+
class BigDecimal
|
7
|
+
def self.json_create(object)
|
8
|
+
BigDecimal._load object['b']
|
9
|
+
end
|
10
|
+
|
11
|
+
def as_json(*)
|
12
|
+
{
|
13
|
+
JSON.create_id => self.class.name,
|
14
|
+
'b' => _dump,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_json(*)
|
19
|
+
as_json.to_json
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
# OpenStruct serialization/deserialization
|
7
|
+
class OpenStruct
|
8
|
+
|
9
|
+
# Deserializes JSON string by constructing new Struct object with values
|
10
|
+
# <tt>v</tt> serialized by <tt>to_json</tt>.
|
11
|
+
def self.json_create(object)
|
12
|
+
new(object['t'] || object[:t])
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a hash, that will be turned into a JSON object and represent this
|
16
|
+
# object.
|
17
|
+
def as_json(*)
|
18
|
+
klass = self.class.name
|
19
|
+
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
|
20
|
+
{
|
21
|
+
JSON.create_id => klass,
|
22
|
+
't' => table,
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Stores class name (OpenStruct) with this struct's values <tt>v</tt> as a
|
27
|
+
# JSON string.
|
28
|
+
def to_json(*args)
|
29
|
+
as_json.to_json(*args)
|
30
|
+
end
|
31
|
+
end
|
data/lib/json/add/time.rb
CHANGED
@@ -10,8 +10,8 @@ class Time
|
|
10
10
|
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
|
11
11
|
object['n'] = usec * 1000
|
12
12
|
end
|
13
|
-
if
|
14
|
-
at(
|
13
|
+
if instance_methods.include?(:tv_nsec)
|
14
|
+
at(object['s'], Rational(object['n'], 1000))
|
15
15
|
else
|
16
16
|
at(object['s'], object['n'] / 1000)
|
17
17
|
end
|
data/lib/json/common.rb
CHANGED
@@ -284,22 +284,40 @@ module JSON
|
|
284
284
|
module_function :pretty_unparse
|
285
285
|
# :startdoc:
|
286
286
|
|
287
|
+
class << self
|
288
|
+
# The global default options for the JSON.load method:
|
289
|
+
# :max_nesting: false
|
290
|
+
# :allow_nan: true
|
291
|
+
# :quirks_mode: true
|
292
|
+
attr_accessor :load_default_options
|
293
|
+
end
|
294
|
+
self.load_default_options = {
|
295
|
+
:max_nesting => false,
|
296
|
+
:allow_nan => true,
|
297
|
+
:quirks_mode => true,
|
298
|
+
}
|
299
|
+
|
287
300
|
# Load a ruby data structure from a JSON _source_ and return it. A source can
|
288
301
|
# either be a string-like object, an IO-like object, or an object responding
|
289
302
|
# to the read method. If _proc_ was given, it will be called with any nested
|
290
|
-
# Ruby object as an argument recursively in depth first order.
|
303
|
+
# Ruby object as an argument recursively in depth first order. The default
|
304
|
+
# options for the parser can be changed via the load_default_options method.
|
291
305
|
#
|
292
306
|
# This method is part of the implementation of the load/dump interface of
|
293
307
|
# Marshal and YAML.
|
294
308
|
def load(source, proc = nil)
|
309
|
+
opts = load_default_options
|
295
310
|
if source.respond_to? :to_str
|
296
311
|
source = source.to_str
|
297
312
|
elsif source.respond_to? :to_io
|
298
313
|
source = source.to_io.read
|
299
|
-
|
314
|
+
elsif source.respond_to?(:read)
|
300
315
|
source = source.read
|
301
316
|
end
|
302
|
-
|
317
|
+
if opts[:quirks_mode] && (source.nil? || source.empty?)
|
318
|
+
source = 'null'
|
319
|
+
end
|
320
|
+
result = parse(source, opts)
|
303
321
|
recurse_proc(result, &proc) if proc
|
304
322
|
result
|
305
323
|
end
|
@@ -321,6 +339,19 @@ module JSON
|
|
321
339
|
alias restore load
|
322
340
|
module_function :restore
|
323
341
|
|
342
|
+
class << self
|
343
|
+
# The global default options for the JSON.dump method:
|
344
|
+
# :max_nesting: false
|
345
|
+
# :allow_nan: true
|
346
|
+
# :quirks_mode: true
|
347
|
+
attr_accessor :dump_default_options
|
348
|
+
end
|
349
|
+
self.dump_default_options = {
|
350
|
+
:max_nesting => false,
|
351
|
+
:allow_nan => true,
|
352
|
+
:quirks_mode => true,
|
353
|
+
}
|
354
|
+
|
324
355
|
# Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
|
325
356
|
# the result.
|
326
357
|
#
|
@@ -331,6 +362,9 @@ module JSON
|
|
331
362
|
# exception is raised. This argument is similar (but not exactly the
|
332
363
|
# same!) to the _limit_ argument in Marshal.dump.
|
333
364
|
#
|
365
|
+
# The default options for the generator can be changed via the
|
366
|
+
# dump_default_options method.
|
367
|
+
#
|
334
368
|
# This method is part of the implementation of the load/dump interface of
|
335
369
|
# Marshal and YAML.
|
336
370
|
def dump(obj, anIO = nil, limit = nil)
|
@@ -341,8 +375,9 @@ module JSON
|
|
341
375
|
anIO = nil
|
342
376
|
end
|
343
377
|
end
|
344
|
-
|
345
|
-
|
378
|
+
opts = JSON.dump_default_options
|
379
|
+
limit and opts.update(:max_nesting => limit)
|
380
|
+
result = generate(obj, opts)
|
346
381
|
if anIO
|
347
382
|
anIO.write result
|
348
383
|
anIO
|
data/lib/json/ext/.keep
ADDED
File without changes
|
data/lib/json/ext.rb
CHANGED
data/lib/json/pure/generator.rb
CHANGED
@@ -136,14 +136,15 @@ module JSON
|
|
136
136
|
# * *quirks_mode*: Enables quirks_mode for parser, that is for example
|
137
137
|
# generating single JSON values instead of documents is possible.
|
138
138
|
def initialize(opts = {})
|
139
|
-
@indent
|
140
|
-
@space
|
141
|
-
@space_before
|
142
|
-
@object_nl
|
143
|
-
@array_nl
|
144
|
-
@allow_nan
|
145
|
-
@ascii_only
|
146
|
-
@quirks_mode
|
139
|
+
@indent = ''
|
140
|
+
@space = ''
|
141
|
+
@space_before = ''
|
142
|
+
@object_nl = ''
|
143
|
+
@array_nl = ''
|
144
|
+
@allow_nan = false
|
145
|
+
@ascii_only = false
|
146
|
+
@quirks_mode = false
|
147
|
+
@buffer_initial_length = 1024
|
147
148
|
configure opts
|
148
149
|
end
|
149
150
|
|
@@ -172,6 +173,16 @@ module JSON
|
|
172
173
|
# it's disabled.
|
173
174
|
attr_accessor :quirks_mode
|
174
175
|
|
176
|
+
# :stopdoc:
|
177
|
+
attr_reader :buffer_initial_length
|
178
|
+
|
179
|
+
def buffer_initial_length=(length)
|
180
|
+
if length > 0
|
181
|
+
@buffer_initial_length = length
|
182
|
+
end
|
183
|
+
end
|
184
|
+
# :startdoc:
|
185
|
+
|
175
186
|
# This integer returns the current depth data structure nesting in the
|
176
187
|
# generated JSON.
|
177
188
|
attr_accessor :depth
|
@@ -233,7 +244,7 @@ module JSON
|
|
233
244
|
# passed to the configure method.
|
234
245
|
def to_h
|
235
246
|
result = {}
|
236
|
-
for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only quirks_mode depth]
|
247
|
+
for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only quirks_mode buffer_initial_length depth]
|
237
248
|
result[iv.intern] = instance_variable_get("@#{iv}")
|
238
249
|
end
|
239
250
|
result
|
data/lib/json/pure/parser.rb
CHANGED
@@ -73,7 +73,7 @@ module JSON
|
|
73
73
|
def initialize(source, opts = {})
|
74
74
|
opts ||= {}
|
75
75
|
unless @quirks_mode = opts[:quirks_mode]
|
76
|
-
source =
|
76
|
+
source = convert_encoding source
|
77
77
|
end
|
78
78
|
super source
|
79
79
|
if !opts.key?(:max_nesting) # defaults to 19
|
@@ -145,7 +145,12 @@ module JSON
|
|
145
145
|
|
146
146
|
private
|
147
147
|
|
148
|
-
def
|
148
|
+
def convert_encoding(source)
|
149
|
+
if source.respond_to?(:to_str)
|
150
|
+
source = source.to_str
|
151
|
+
else
|
152
|
+
raise TypeError, "#{source.inspect} is not like a string"
|
153
|
+
end
|
149
154
|
if defined?(::Encoding)
|
150
155
|
if source.encoding == ::Encoding::ASCII_8BIT
|
151
156
|
b = source[0, 4].bytes.to_a
|
data/lib/json/pure.rb
CHANGED
data/lib/json/version.rb
CHANGED
data/tests/test_json.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
require 'test/unit'
|
5
5
|
require File.join(File.dirname(__FILE__), 'setup_variant')
|
6
6
|
require 'stringio'
|
7
|
+
require 'tempfile'
|
7
8
|
|
8
9
|
unless Array.method_defined?(:permutation)
|
9
10
|
begin
|
@@ -107,6 +108,8 @@ class TC_JSON < Test::Unit::TestCase
|
|
107
108
|
def test_parse_json_primitive_values
|
108
109
|
assert_raise(JSON::ParserError) { JSON.parse('') }
|
109
110
|
assert_raise(JSON::ParserError) { JSON.parse('', :quirks_mode => true) }
|
111
|
+
assert_raise(TypeError) { JSON.parse(nil) }
|
112
|
+
assert_raise(TypeError) { JSON.parse(nil, :quirks_mode => true) }
|
110
113
|
assert_raise(JSON::ParserError) { JSON.parse(' /* foo */ ') }
|
111
114
|
assert_raise(JSON::ParserError) { JSON.parse(' /* foo */ ', :quirks_mode => true) }
|
112
115
|
parser = JSON::Parser.new('null')
|
@@ -414,7 +417,20 @@ EOT
|
|
414
417
|
JSON.parse('{"foo":"bar", "baz":"quux"}', :symbolize_names => true))
|
415
418
|
end
|
416
419
|
|
417
|
-
def
|
420
|
+
def test_load
|
421
|
+
assert_equal @hash, JSON.load(@json)
|
422
|
+
tempfile = Tempfile.open('json')
|
423
|
+
tempfile.write @json
|
424
|
+
tempfile.rewind
|
425
|
+
assert_equal @hash, JSON.load(tempfile)
|
426
|
+
stringio = StringIO.new(@json)
|
427
|
+
stringio.rewind
|
428
|
+
assert_equal @hash, JSON.load(stringio)
|
429
|
+
assert_equal nil, JSON.load(nil)
|
430
|
+
assert_equal nil, JSON.load('')
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_dump
|
418
434
|
too_deep = '[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]'
|
419
435
|
assert_equal too_deep, JSON.dump(eval(too_deep))
|
420
436
|
assert_kind_of String, Marshal.dump(eval(too_deep))
|