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.

@@ -3,16 +3,10 @@
3
3
 
4
4
  #include "ruby.h"
5
5
 
6
- #if HAVE_RE_H
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
- *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;
@@ -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
 
@@ -1,24 +1,24 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{json}
5
- s.version = "1.6.1"
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 = [%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-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
@@ -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.2"
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-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
@@ -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
@@ -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
- else
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, :max_nesting => false, :allow_nan => true)
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
- limit ||= 0
345
- result = generate(obj, :allow_nan => true, :max_nesting => limit)
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
@@ -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
File without changes
@@ -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'
@@ -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