json-maglev- 1.6.1 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- *result = rb_Integer(rb_str_new(json->memo, len));
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
- *result = rb_Float(rb_str_new(json->memo, len));
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 = Qnil;
819
- json->Vsource = Qnil;
820
- json->create_id = Qnil;
821
- json->object_class = Qnil;
822
- json->array_class = Qnil;
823
- json->match_string = Qnil;
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 = %q{json-maglev-}
5
- s.version = "1.6.1"
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 = [%q{Florian Frank}]
9
- s.date = %q{2011-09-18}
10
- s.description = %q{This is a JSON implementation as a Ruby extension in C.}
11
- s.email = %q{flori@ping.de}
12
- s.extensions = [%q{ext/json/ext/parser/extconf.rb}, %q{ext/json/ext/generator/extconf.rb}]
13
- s.extra_rdoc_files = [%q{README.rdoc}]
14
- s.files = [%q{tests}, %q{tests/test_json_string_matching.rb}, %q{tests/test_json_fixtures.rb}, %q{tests/setup_variant.rb}, %q{tests/fixtures}, %q{tests/fixtures/fail6.json}, %q{tests/fixtures/fail9.json}, %q{tests/fixtures/fail10.json}, %q{tests/fixtures/fail24.json}, %q{tests/fixtures/fail28.json}, %q{tests/fixtures/fail13.json}, %q{tests/fixtures/fail4.json}, %q{tests/fixtures/pass3.json}, %q{tests/fixtures/fail11.json}, %q{tests/fixtures/fail14.json}, %q{tests/fixtures/fail3.json}, %q{tests/fixtures/fail12.json}, %q{tests/fixtures/pass16.json}, %q{tests/fixtures/pass15.json}, %q{tests/fixtures/fail20.json}, %q{tests/fixtures/fail8.json}, %q{tests/fixtures/pass2.json}, %q{tests/fixtures/fail5.json}, %q{tests/fixtures/fail1.json}, %q{tests/fixtures/fail25.json}, %q{tests/fixtures/pass17.json}, %q{tests/fixtures/fail7.json}, %q{tests/fixtures/pass26.json}, %q{tests/fixtures/fail21.json}, %q{tests/fixtures/pass1.json}, %q{tests/fixtures/fail23.json}, %q{tests/fixtures/fail18.json}, %q{tests/fixtures/fail2.json}, %q{tests/fixtures/fail22.json}, %q{tests/fixtures/fail27.json}, %q{tests/fixtures/fail19.json}, %q{tests/test_json_unicode.rb}, %q{tests/test_json_addition.rb}, %q{tests/test_json_generate.rb}, %q{tests/test_json_encoding.rb}, %q{tests/test_json.rb}, %q{COPYING}, %q{TODO}, %q{Rakefile}, %q{benchmarks}, %q{benchmarks/data-p4-3GHz-ruby18}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat}, %q{benchmarks/parser2_benchmark.rb}, %q{benchmarks/parser_benchmark.rb}, %q{benchmarks/generator2_benchmark.rb}, %q{benchmarks/generator_benchmark.rb}, %q{benchmarks/ohai.ruby}, %q{benchmarks/data}, %q{benchmarks/ohai.json}, %q{lib}, %q{lib/json}, %q{lib/json/version.rb}, %q{lib/json/add}, %q{lib/json/add/symbol.rb}, %q{lib/json/add/struct.rb}, %q{lib/json/add/complex.rb}, %q{lib/json/add/rational.rb}, %q{lib/json/add/exception.rb}, %q{lib/json/add/time.rb}, %q{lib/json/add/date_time.rb}, %q{lib/json/add/core.rb}, %q{lib/json/add/range.rb}, %q{lib/json/add/date.rb}, %q{lib/json/add/regexp.rb}, %q{lib/json/common.rb}, %q{lib/json/pure}, %q{lib/json/pure/generator.rb}, %q{lib/json/pure/parser.rb}, %q{lib/json/ext.rb}, %q{lib/json/pure.rb}, %q{lib/json/ext}, %q{lib/json.rb}, %q{Gemfile}, %q{README.rdoc}, %q{json_pure.gemspec}, %q{GPL}, %q{CHANGES}, %q{COPYING-json-jruby}, %q{ext}, %q{ext/json}, %q{ext/json/ext}, %q{ext/json/ext/parser}, %q{ext/json/ext/parser/parser.h}, %q{ext/json/ext/parser/extconf.rb}, %q{ext/json/ext/parser/parser.rl}, %q{ext/json/ext/parser/parser.c}, %q{ext/json/ext/generator}, %q{ext/json/ext/generator/generator.c}, %q{ext/json/ext/generator/extconf.rb}, %q{ext/json/ext/generator/generator.h}, %q{VERSION}, %q{data}, %q{data/prototype.js}, %q{data/index.html}, %q{data/example.json}, %q{json.gemspec}, %q{java}, %q{java/src}, %q{java/src/json}, %q{java/src/json/ext}, %q{java/src/json/ext/Parser.java}, %q{java/src/json/ext/RuntimeInfo.java}, %q{java/src/json/ext/GeneratorState.java}, %q{java/src/json/ext/OptionsReader.java}, %q{java/src/json/ext/ParserService.java}, %q{java/src/json/ext/Parser.rl}, %q{java/src/json/ext/StringEncoder.java}, %q{java/src/json/ext/GeneratorService.java}, %q{java/src/json/ext/Utils.java}, %q{java/src/json/ext/StringDecoder.java}, %q{java/src/json/ext/Generator.java}, %q{java/src/json/ext/ByteListTranscoder.java}, %q{java/src/json/ext/GeneratorMethods.java}, %q{java/lib}, %q{java/lib/bytelist-1.0.6.jar}, %q{java/lib/jcodings.jar}, %q{diagrams}, %q{README-json-jruby.markdown}, %q{install.rb}, %q{json-java.gemspec}, %q{tools}, %q{tools/fuzz.rb}, %q{tools/server.rb}, %q{./tests/test_json_string_matching.rb}, %q{./tests/test_json_fixtures.rb}, %q{./tests/test_json_unicode.rb}, %q{./tests/test_json_addition.rb}, %q{./tests/test_json_generate.rb}, %q{./tests/test_json_encoding.rb}, %q{./tests/test_json.rb}]
15
- s.homepage = %q{http://flori.github.com/json}
16
- s.rdoc_options = [%q{--title}, %q{JSON implemention for Ruby}, %q{--main}, %q{README.rdoc}]
17
- s.require_paths = [%q{ext/json/ext}, %q{ext}, %q{lib}]
18
- s.rubyforge_project = %q{json}
19
- s.rubygems_version = %q{1.8.6}
20
- s.summary = %q{JSON Implementation for Ruby}
21
- s.test_files = [%q{./tests/test_json_string_matching.rb}, %q{./tests/test_json_fixtures.rb}, %q{./tests/test_json_unicode.rb}, %q{./tests/test_json_addition.rb}, %q{./tests/test_json_generate.rb}, %q{./tests/test_json_encoding.rb}, %q{./tests/test_json.rb}]
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 = %q{json_pure}
5
- s.version = "1.6.1"
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 = [%q{Florian Frank}]
9
- s.date = %q{2011-09-18}
10
- s.description = %q{This is a JSON implementation in pure Ruby.}
11
- s.email = %q{flori@ping.de}
12
- s.extra_rdoc_files = [%q{README.rdoc}]
13
- s.files = [%q{tests}, %q{tests/test_json_string_matching.rb}, %q{tests/test_json_fixtures.rb}, %q{tests/setup_variant.rb}, %q{tests/fixtures}, %q{tests/fixtures/fail6.json}, %q{tests/fixtures/fail9.json}, %q{tests/fixtures/fail10.json}, %q{tests/fixtures/fail24.json}, %q{tests/fixtures/fail28.json}, %q{tests/fixtures/fail13.json}, %q{tests/fixtures/fail4.json}, %q{tests/fixtures/pass3.json}, %q{tests/fixtures/fail11.json}, %q{tests/fixtures/fail14.json}, %q{tests/fixtures/fail3.json}, %q{tests/fixtures/fail12.json}, %q{tests/fixtures/pass16.json}, %q{tests/fixtures/pass15.json}, %q{tests/fixtures/fail20.json}, %q{tests/fixtures/fail8.json}, %q{tests/fixtures/pass2.json}, %q{tests/fixtures/fail5.json}, %q{tests/fixtures/fail1.json}, %q{tests/fixtures/fail25.json}, %q{tests/fixtures/pass17.json}, %q{tests/fixtures/fail7.json}, %q{tests/fixtures/pass26.json}, %q{tests/fixtures/fail21.json}, %q{tests/fixtures/pass1.json}, %q{tests/fixtures/fail23.json}, %q{tests/fixtures/fail18.json}, %q{tests/fixtures/fail2.json}, %q{tests/fixtures/fail22.json}, %q{tests/fixtures/fail27.json}, %q{tests/fixtures/fail19.json}, %q{tests/test_json_unicode.rb}, %q{tests/test_json_addition.rb}, %q{tests/test_json_generate.rb}, %q{tests/test_json_encoding.rb}, %q{tests/test_json.rb}, %q{COPYING}, %q{TODO}, %q{Rakefile}, %q{benchmarks}, %q{benchmarks/data-p4-3GHz-ruby18}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat}, %q{benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat}, %q{benchmarks/parser2_benchmark.rb}, %q{benchmarks/parser_benchmark.rb}, %q{benchmarks/generator2_benchmark.rb}, %q{benchmarks/generator_benchmark.rb}, %q{benchmarks/ohai.ruby}, %q{benchmarks/data}, %q{benchmarks/ohai.json}, %q{lib}, %q{lib/json}, %q{lib/json/version.rb}, %q{lib/json/add}, %q{lib/json/add/symbol.rb}, %q{lib/json/add/struct.rb}, %q{lib/json/add/complex.rb}, %q{lib/json/add/rational.rb}, %q{lib/json/add/exception.rb}, %q{lib/json/add/time.rb}, %q{lib/json/add/date_time.rb}, %q{lib/json/add/core.rb}, %q{lib/json/add/range.rb}, %q{lib/json/add/date.rb}, %q{lib/json/add/regexp.rb}, %q{lib/json/common.rb}, %q{lib/json/pure}, %q{lib/json/pure/generator.rb}, %q{lib/json/pure/parser.rb}, %q{lib/json/ext.rb}, %q{lib/json/pure.rb}, %q{lib/json/ext}, %q{lib/json.rb}, %q{Gemfile}, %q{README.rdoc}, %q{json_pure.gemspec}, %q{GPL}, %q{CHANGES}, %q{COPYING-json-jruby}, %q{ext}, %q{ext/json}, %q{ext/json/ext}, %q{ext/json/ext/parser}, %q{ext/json/ext/parser/parser.h}, %q{ext/json/ext/parser/extconf.rb}, %q{ext/json/ext/parser/parser.rl}, %q{ext/json/ext/parser/parser.c}, %q{ext/json/ext/generator}, %q{ext/json/ext/generator/generator.c}, %q{ext/json/ext/generator/extconf.rb}, %q{ext/json/ext/generator/generator.h}, %q{VERSION}, %q{data}, %q{data/prototype.js}, %q{data/index.html}, %q{data/example.json}, %q{json.gemspec}, %q{java}, %q{java/src}, %q{java/src/json}, %q{java/src/json/ext}, %q{java/src/json/ext/Parser.java}, %q{java/src/json/ext/RuntimeInfo.java}, %q{java/src/json/ext/GeneratorState.java}, %q{java/src/json/ext/OptionsReader.java}, %q{java/src/json/ext/ParserService.java}, %q{java/src/json/ext/Parser.rl}, %q{java/src/json/ext/StringEncoder.java}, %q{java/src/json/ext/GeneratorService.java}, %q{java/src/json/ext/Utils.java}, %q{java/src/json/ext/StringDecoder.java}, %q{java/src/json/ext/Generator.java}, %q{java/src/json/ext/ByteListTranscoder.java}, %q{java/src/json/ext/GeneratorMethods.java}, %q{java/lib}, %q{java/lib/bytelist-1.0.6.jar}, %q{java/lib/jcodings.jar}, %q{diagrams}, %q{README-json-jruby.markdown}, %q{install.rb}, %q{json-java.gemspec}, %q{tools}, %q{tools/fuzz.rb}, %q{tools/server.rb}, %q{./tests/test_json_string_matching.rb}, %q{./tests/test_json_fixtures.rb}, %q{./tests/test_json_unicode.rb}, %q{./tests/test_json_addition.rb}, %q{./tests/test_json_generate.rb}, %q{./tests/test_json_encoding.rb}, %q{./tests/test_json.rb}]
14
- s.homepage = %q{http://flori.github.com/json}
15
- s.rdoc_options = [%q{--title}, %q{JSON implemention for ruby}, %q{--main}, %q{README.rdoc}]
16
- s.require_paths = [%q{lib}]
17
- s.rubyforge_project = %q{json}
18
- s.rubygems_version = %q{1.8.6}
19
- s.summary = %q{JSON Implementation for Ruby}
20
- s.test_files = [%q{./tests/test_json_string_matching.rb}, %q{./tests/test_json_fixtures.rb}, %q{./tests/test_json_unicode.rb}, %q{./tests/test_json_addition.rb}, %q{./tests/test_json_generate.rb}, %q{./tests/test_json_encoding.rb}, %q{./tests/test_json.rb}]
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 respond_to?(:tv_nsec)
14
- at(*object.values_at('s', 'n'))
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
- else
314
+ elsif source.respond_to?(:read)
300
315
  source = source.read
301
316
  end
302
- result = parse(source, :max_nesting => false, :allow_nan => true)
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
- limit ||= 0
345
- result = generate(obj, :allow_nan => true, :max_nesting => limit)
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
File without changes
data/lib/json/ext.rb CHANGED
@@ -1,3 +1,9 @@
1
+ if ENV['SIMPLECOV_COVERAGE'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/tests/"
5
+ end
6
+ end
1
7
  require 'json/common'
2
8
 
3
9
  module JSON
@@ -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 = false
145
- @ascii_only = false
146
- @quirks_mode = false
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
@@ -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 = determine_encoding 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 determine_encoding(source)
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
@@ -1,3 +1,9 @@
1
+ if ENV['SIMPLECOV_COVERAGE'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "/tests/"
5
+ end
6
+ end
1
7
  require 'json/common'
2
8
  require 'json/pure/parser'
3
9
  require 'json/pure/generator'
data/lib/json/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module JSON
2
2
  # JSON version
3
- VERSION = '1.6.1'
3
+ VERSION = '1.6.3'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
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 test_load_dump
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))