json 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of json might be problematic. Click here for more details.
- data/.gitignore +8 -0
- data/.travis.yml +15 -0
- data/CHANGES +10 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -2
- data/VERSION +1 -1
- data/benchmarks/data-p4-3GHz-ruby18/.keep +0 -0
- data/benchmarks/data/.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/extconf.rb +0 -7
- data/ext/json/ext/generator/generator.c +57 -132
- data/ext/json/ext/generator/generator.h +4 -43
- data/ext/json/ext/parser/extconf.rb +0 -3
- data/ext/json/ext/parser/parser.c +94 -87
- data/ext/json/ext/parser/parser.h +2 -7
- data/ext/json/ext/parser/parser.rl +12 -2
- 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 +39 -5
- data/lib/json/ext.rb +6 -0
- data/lib/json/ext/.keep +0 -0
- data/lib/json/pure.rb +6 -0
- data/lib/json/pure/generator.rb +20 -9
- data/lib/json/pure/parser.rb +7 -2
- data/lib/json/version.rb +1 -1
- data/tests/test_json.rb +16 -1
- data/tests/test_json_addition.rb +15 -1
- data/tests/test_json_generate.rb +66 -30
- metadata +142 -133
@@ -3,16 +3,10 @@
|
|
3
3
|
|
4
4
|
#include "ruby.h"
|
5
5
|
|
6
|
-
#
|
6
|
+
#ifndef HAVE_RUBY_RE_H
|
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
|
@@ -49,6 +43,7 @@ typedef struct JSON_ParserStruct {
|
|
49
43
|
VALUE array_class;
|
50
44
|
int create_additions;
|
51
45
|
VALUE match_string;
|
46
|
+
FBuffer *fbuffer;
|
52
47
|
} JSON_Parser;
|
53
48
|
|
54
49
|
#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;
|
@@ -688,6 +695,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
688
695
|
json->object_class = Qnil;
|
689
696
|
json->array_class = Qnil;
|
690
697
|
}
|
698
|
+
source = rb_convert_type(source, T_STRING, "String", "to_str");
|
691
699
|
if (!json->quirks_mode) {
|
692
700
|
source = convert_encoding(StringValue(source));
|
693
701
|
}
|
@@ -805,6 +813,7 @@ static JSON_Parser *JSON_allocate()
|
|
805
813
|
{
|
806
814
|
JSON_Parser *json = ALLOC(JSON_Parser);
|
807
815
|
MEMZERO(json, JSON_Parser, 1);
|
816
|
+
json->fbuffer = fbuffer_alloc(0);
|
808
817
|
return json;
|
809
818
|
}
|
810
819
|
|
@@ -819,6 +828,7 @@ static void JSON_mark(JSON_Parser *json)
|
|
819
828
|
|
820
829
|
static void JSON_free(JSON_Parser *json)
|
821
830
|
{
|
831
|
+
fbuffer_free(json->fbuffer);
|
822
832
|
ruby_xfree(json);
|
823
833
|
}
|
824
834
|
|
@@ -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"
|
5
|
+
s.version = "1.6.2"
|
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-11-28"
|
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/generator/extconf.rb", "ext/json/ext/parser/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.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"]
|
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.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"]
|
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.2"
|
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-11-28"
|
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.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"]
|
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.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"]
|
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,39 @@ 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
|
316
|
+
elsif source.nil? && opts[:quirks_mode]
|
317
|
+
source = 'null'
|
301
318
|
end
|
302
|
-
result = parse(source,
|
319
|
+
result = parse(source, opts)
|
303
320
|
recurse_proc(result, &proc) if proc
|
304
321
|
result
|
305
322
|
end
|
@@ -321,6 +338,19 @@ module JSON
|
|
321
338
|
alias restore load
|
322
339
|
module_function :restore
|
323
340
|
|
341
|
+
class << self
|
342
|
+
# The global default options for the JSON.dump method:
|
343
|
+
# :max_nesting: false
|
344
|
+
# :allow_nan: true
|
345
|
+
# :quirks_mode: true
|
346
|
+
attr_accessor :dump_default_options
|
347
|
+
end
|
348
|
+
self.dump_default_options = {
|
349
|
+
:max_nesting => false,
|
350
|
+
:allow_nan => true,
|
351
|
+
:quirks_mode => true,
|
352
|
+
}
|
353
|
+
|
324
354
|
# Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
|
325
355
|
# the result.
|
326
356
|
#
|
@@ -331,6 +361,9 @@ module JSON
|
|
331
361
|
# exception is raised. This argument is similar (but not exactly the
|
332
362
|
# same!) to the _limit_ argument in Marshal.dump.
|
333
363
|
#
|
364
|
+
# The default options for the generator can be changed via the
|
365
|
+
# dump_default_options method.
|
366
|
+
#
|
334
367
|
# This method is part of the implementation of the load/dump interface of
|
335
368
|
# Marshal and YAML.
|
336
369
|
def dump(obj, anIO = nil, limit = nil)
|
@@ -341,8 +374,9 @@ module JSON
|
|
341
374
|
anIO = nil
|
342
375
|
end
|
343
376
|
end
|
344
|
-
|
345
|
-
|
377
|
+
opts = JSON.dump_default_options
|
378
|
+
limit and opts.update(:max_nesting => limit)
|
379
|
+
result = generate(obj, opts)
|
346
380
|
if anIO
|
347
381
|
anIO.write result
|
348
382
|
anIO
|
data/lib/json/ext.rb
CHANGED
data/lib/json/ext/.keep
ADDED
File without changes
|
data/lib/json/pure.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
|