diff options
-rw-r--r-- | ext/json/ext/generator/generator.c | 47 | ||||
-rw-r--r-- | ext/json/ext/generator/generator.h | 1 | ||||
-rw-r--r-- | java/src/json/ext/Generator.java | 6 | ||||
-rw-r--r-- | java/src/json/ext/GeneratorMethods.java | 4 | ||||
-rw-r--r-- | java/src/json/ext/GeneratorService.java | 2 | ||||
-rw-r--r-- | java/src/json/ext/GeneratorState.java | 46 | ||||
-rw-r--r-- | java/src/json/ext/OptionsReader.java | 2 | ||||
-rw-r--r-- | java/src/json/ext/Parser.java | 74 | ||||
-rw-r--r-- | java/src/json/ext/Parser.rl | 30 | ||||
-rw-r--r-- | java/src/json/ext/ParserService.java | 2 | ||||
-rw-r--r-- | java/src/json/ext/Utils.java | 2 | ||||
-rw-r--r-- | json.gemspec | 20 | ||||
-rw-r--r-- | json_pure.gemspec | 18 | ||||
-rw-r--r-- | lib/json/common.rb | 18 | ||||
-rw-r--r-- | lib/json/pure/generator.rb | 17 | ||||
-rwxr-xr-x | tests/test_json_generate.rb | 22 |
16 files changed, 207 insertions, 104 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c index 4e44178..26b667b 100644 --- a/ext/json/ext/generator/generator.c +++ b/ext/json/ext/generator/generator.c @@ -13,8 +13,8 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject, static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before, i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only, - i_pack, i_unpack, i_create_id, i_extend, i_key_p, i_aref, i_send, - i_respond_to_p, i_match, i_keys, i_depth, i_dup; + i_quirks_mode, i_pack, i_unpack, i_create_id, i_extend, i_key_p, + i_aref, i_send, i_respond_to_p, i_match, i_keys, i_depth, i_dup; /* * Copyright 2001-2004 Unicode, Inc. @@ -688,6 +688,8 @@ static VALUE cState_configure(VALUE self, VALUE opts) state->allow_nan = RTEST(tmp); tmp = rb_hash_aref(opts, ID2SYM(i_ascii_only)); state->ascii_only = RTEST(tmp); + tmp = rb_hash_aref(opts, ID2SYM(i_quirks_mode)); + state->quirks_mode = RTEST(tmp); return self; } @@ -708,6 +710,7 @@ static VALUE cState_to_h(VALUE self) rb_hash_aset(result, ID2SYM(i_array_nl), rb_str_new(state->array_nl, state->array_nl_len)); rb_hash_aset(result, ID2SYM(i_allow_nan), state->allow_nan ? Qtrue : Qfalse); rb_hash_aset(result, ID2SYM(i_ascii_only), state->ascii_only ? Qtrue : Qfalse); + rb_hash_aset(result, ID2SYM(i_quirks_mode), state->quirks_mode ? Qtrue : Qfalse); rb_hash_aset(result, ID2SYM(i_max_nesting), LONG2FIX(state->max_nesting)); rb_hash_aset(result, ID2SYM(i_depth), LONG2FIX(state->depth)); return result; @@ -961,11 +964,14 @@ static VALUE cState_generate(VALUE self, VALUE obj) { VALUE result = cState_partial_generate(self, obj); VALUE re, args[2]; - args[0] = rb_str_new2("\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z"); - args[1] = CRegexp_MULTILINE; - re = rb_class_new_instance(2, args, rb_cRegexp); - if (NIL_P(rb_funcall(re, i_match, 1, result))) { - rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed"); + GET_STATE(self); + if (!state->quirks_mode) { + args[0] = rb_str_new2("\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z"); + args[1] = CRegexp_MULTILINE; + re = rb_class_new_instance(2, args, rb_cRegexp); + if (NIL_P(rb_funcall(re, i_match, 1, result))) { + rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed"); + } } return result; } @@ -1288,6 +1294,29 @@ static VALUE cState_ascii_only_p(VALUE self) } /* + * call-seq: quirks_mode? + * + * Returns true, if quirks mode is enabled. Otherwise returns false. + */ +static VALUE cState_quirks_mode_p(VALUE self) +{ + GET_STATE(self); + return state->quirks_mode ? Qtrue : Qfalse; +} + +/* + * call-seq: quirks_mode=(enable) + * + * If set to true, enables the quirks_mode mode. + */ +static VALUE cState_quirks_mode_set(VALUE self, VALUE enable) +{ + GET_STATE(self); + state->quirks_mode = RTEST(enable); + return Qnil; +} + +/* * call-seq: depth * * This integer returns the current depth of data structure nesting. @@ -1345,6 +1374,9 @@ void Init_generator() rb_define_method(cState, "check_circular?", cState_check_circular_p, 0); rb_define_method(cState, "allow_nan?", cState_allow_nan_p, 0); rb_define_method(cState, "ascii_only?", cState_ascii_only_p, 0); + rb_define_method(cState, "quirks_mode?", cState_quirks_mode_p, 0); + rb_define_method(cState, "quirks_mode", cState_quirks_mode_p, 0); + rb_define_method(cState, "quirks_mode=", cState_quirks_mode_set, 1); rb_define_method(cState, "depth", cState_depth, 0); rb_define_method(cState, "depth=", cState_depth_set, 1); rb_define_method(cState, "configure", cState_configure, 1); @@ -1392,6 +1424,7 @@ void Init_generator() i_max_nesting = rb_intern("max_nesting"); i_allow_nan = rb_intern("allow_nan"); i_ascii_only = rb_intern("ascii_only"); + i_quirks_mode = rb_intern("quirks_mode"); i_depth = rb_intern("depth"); i_pack = rb_intern("pack"); i_unpack = rb_intern("unpack"); diff --git a/ext/json/ext/generator/generator.h b/ext/json/ext/generator/generator.h index ee496fe..6379f05 100644 --- a/ext/json/ext/generator/generator.h +++ b/ext/json/ext/generator/generator.h @@ -123,6 +123,7 @@ typedef struct JSON_Generator_StateStruct { long max_nesting; char allow_nan; char ascii_only; + char quirks_mode; long depth; } JSON_Generator_State; diff --git a/java/src/json/ext/Generator.java b/java/src/json/ext/Generator.java index fbc394f..78dc078 100644 --- a/java/src/json/ext/Generator.java +++ b/java/src/json/ext/Generator.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ @@ -85,11 +85,11 @@ public final class Generator { /** * A class that concentrates all the information that is shared by * generators working on a single session. - * + * * <p>A session is defined as the process of serializing a single root * object; any handler directly called by container handlers (arrays and * hashes/objects) shares this object with its caller. - * + * * <p>Note that anything called indirectly (via {@link GENERIC_HANDLER}) * won't be part of the session. */ diff --git a/java/src/json/ext/GeneratorMethods.java b/java/src/json/ext/GeneratorMethods.java index 356f2d0..637b579 100644 --- a/java/src/json/ext/GeneratorMethods.java +++ b/java/src/json/ext/GeneratorMethods.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ @@ -25,7 +25,7 @@ import org.jruby.util.ByteList; /** * A class that populates the * <code>Json::Ext::Generator::GeneratorMethods</code> module. - * + * * @author mernen */ class GeneratorMethods { diff --git a/java/src/json/ext/GeneratorService.java b/java/src/json/ext/GeneratorService.java index 2f3b07e..ed33639 100644 --- a/java/src/json/ext/GeneratorService.java +++ b/java/src/json/ext/GeneratorService.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ diff --git a/java/src/json/ext/GeneratorState.java b/java/src/json/ext/GeneratorState.java index f04eda2..a53ff12 100644 --- a/java/src/json/ext/GeneratorState.java +++ b/java/src/json/ext/GeneratorState.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ @@ -24,10 +24,10 @@ import org.jruby.util.ByteList; /** * The <code>JSON::Ext::Generator::State</code> class. - * + * * <p>This class is used to create State instances, that are use to hold data * while generating a JSON text from a a Ruby data structure. - * + * * @author mernen */ public class GeneratorState extends RubyObject { @@ -76,6 +76,11 @@ public class GeneratorState extends RubyObject { */ private boolean asciiOnly = DEFAULT_ASCII_ONLY; static final boolean DEFAULT_ASCII_ONLY = false; + /** + * XXX + */ + private boolean quirksMode = DEFAULT_QUIRKS_MODE; + static final boolean DEFAULT_QUIRKS_MODE = false; /** * The current depth (inside a #to_json call) @@ -94,7 +99,7 @@ public class GeneratorState extends RubyObject { /** * <code>State.from_state(opts)</code> - * + * * <p>Creates a State object from <code>opts</code>, which ought to be * {@link RubyHash Hash} to create a new <code>State</code> instance * configured by <codes>opts</code>, something else to create an @@ -136,11 +141,11 @@ public class GeneratorState extends RubyObject { /** * <code>State#initialize(opts = {})</code> - * + * * Instantiates a new <code>State</code> object, configured by <code>opts</code>. - * + * * <code>opts</code> can have the following keys: - * + * * <dl> * <dt><code>:indent</code> * <dd>a {@link RubyString String} used to indent levels (default: <code>""</code>) @@ -151,7 +156,7 @@ public class GeneratorState extends RubyObject { * <dd>a String that is put before a <code>":"</code> pair delimiter * (default: <code>""</code>) * <dt><code>:object_nl</code> - * <dd>a String that is put at the end of a JSON object (default: <code>""</code>) + * <dd>a String that is put at the end of a JSON object (default: <code>""</code>) * <dt><code>:array_nl</code> * <dd>a String that is put at the end of a JSON array (default: <code>""</code>) * <dt><code>:allow_nan</code> @@ -181,6 +186,7 @@ public class GeneratorState extends RubyObject { this.maxNesting = orig.maxNesting; this.allowNaN = orig.allowNaN; this.asciiOnly = orig.asciiOnly; + this.quirksMode = orig.quirksMode; this.depth = orig.depth; return this; } @@ -191,7 +197,7 @@ public class GeneratorState extends RubyObject { @JRubyMethod public IRubyObject generate(ThreadContext context, IRubyObject obj) { RubyString result = Generator.generateJson(context, obj, this); - if (!objectOrArrayLiteral(result)) { + if (!quirksMode && !objectOrArrayLiteral(result)) { throw Utils.newException(context, Utils.M_GENERATOR_ERROR, "only generation of JSON objects or arrays allowed"); } @@ -364,6 +370,22 @@ public class GeneratorState extends RubyObject { return context.getRuntime().newBoolean(asciiOnly); } + @JRubyMethod(name="quirks_mode") + public RubyBoolean quirks_mode_get(ThreadContext context) { + return context.getRuntime().newBoolean(quirksMode); + } + + @JRubyMethod(name="quirks_mode=") + public IRubyObject quirks_mode_set(IRubyObject quirks_mode) { + quirksMode = quirks_mode.isTrue(); + return quirks_mode.getRuntime().newBoolean(quirksMode); + } + + @JRubyMethod(name="quirks_mode?") + public RubyBoolean quirks_mode_p(ThreadContext context) { + return context.getRuntime().newBoolean(quirksMode); + } + public int getDepth() { return depth; } @@ -390,7 +412,7 @@ public class GeneratorState extends RubyObject { /** * <code>State#configure(opts)</code> - * + * * <p>Configures this State instance with the {@link RubyHash Hash} * <code>opts</code>, and returns itself. * @param vOpts The options hash @@ -418,6 +440,7 @@ public class GeneratorState extends RubyObject { maxNesting = opts.getInt("max_nesting", DEFAULT_MAX_NESTING); allowNaN = opts.getBool("allow_nan", DEFAULT_ALLOW_NAN); asciiOnly = opts.getBool("ascii_only", DEFAULT_ASCII_ONLY); + quirksMode = opts.getBool("quirks_mode", DEFAULT_QUIRKS_MODE); depth = opts.getInt("depth", 0); @@ -426,7 +449,7 @@ public class GeneratorState extends RubyObject { /** * <code>State#to_h()</code> - * + * * <p>Returns the configuration instance variables as a hash, that can be * passed to the configure method. * @return @@ -443,6 +466,7 @@ public class GeneratorState extends RubyObject { result.op_aset(context, runtime.newSymbol("array_nl"), array_nl_get(context)); result.op_aset(context, runtime.newSymbol("allow_nan"), allow_nan_p(context)); result.op_aset(context, runtime.newSymbol("ascii_only"), ascii_only_p(context)); + result.op_aset(context, runtime.newSymbol("quirks_mode"), quirks_mode_p(context)); result.op_aset(context, runtime.newSymbol("max_nesting"), max_nesting_get(context)); result.op_aset(context, runtime.newSymbol("depth"), depth_get(context)); return result; diff --git a/java/src/json/ext/OptionsReader.java b/java/src/json/ext/OptionsReader.java index c9c9c94..a0b76b1 100644 --- a/java/src/json/ext/OptionsReader.java +++ b/java/src/json/ext/OptionsReader.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java index cea42d4..6f9b30a 100644 --- a/java/src/json/ext/Parser.java +++ b/java/src/json/ext/Parser.java @@ -2,7 +2,7 @@ // line 1 "Parser.rl" /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ @@ -31,16 +31,16 @@ import org.jruby.util.ByteList; /** * The <code>JSON::Ext::Parser</code> class. - * + * * <p>This is the JSON parser implemented as a Java class. To use it as the * standard parser, set * <pre>JSON.parser = JSON::Ext::Parser</pre> * This is performed for you when you <code>include "json/ext"</code>. - * + * * <p>This class does not perform the actual parsing, just acts as an interface * to Ruby code. When the {@link #parse()} method is invoked, a * Parser.ParserSession object is instantiated, which handles the process. - * + * * @author mernen */ public class Parser extends RubyObject { @@ -71,7 +71,7 @@ public class Parser extends RubyObject { /** * Multiple-value return for internal parser methods. - * + * * <p>All the <code>parse<var>Stuff</var></code> methods return instances of * <code>ParserResult</code> when successful, or <code>null</code> when * there's a problem with the input data. @@ -100,18 +100,18 @@ public class Parser extends RubyObject { /** * <code>Parser.new(source, opts = {})</code> - * + * * <p>Creates a new <code>JSON::Ext::Parser</code> instance for the string * <code>source</code>. * It will be configured by the <code>opts</code> Hash. * <code>opts</code> can have the following keys: - * + * * <dl> * <dt><code>:max_nesting</code> * <dd>The maximum depth of nesting allowed in the parsed data * structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>, * it defaults to 19. - * + * * <dt><code>:allow_nan</code> * <dd>If set to <code>true</code>, allow <code>NaN</code>, * <code>Infinity</code> and <code>-Infinity</code> in defiance of RFC 4627 @@ -120,15 +120,15 @@ public class Parser extends RubyObject { * <dt><code>:symbolize_names</code> * <dd>If set to <code>true</code>, returns symbols for the names (keys) in * a JSON object. Otherwise strings are returned, which is also the default. - * + * * <dt><code>:create_additions</code> * <dd>If set to <code>false</code>, the Parser doesn't create additions * even if a matchin class and <code>create_id</code> was found. This option * defaults to <code>true</code>. - * + * * <dt><code>:object_class</code> * <dd>Defaults to Hash. - * + * * <dt><code>:array_class</code> * <dd>Defaults to Array. * </dl> @@ -229,7 +229,7 @@ public class Parser extends RubyObject { /** * <code>Parser#parse()</code> - * + * * <p>Parses the current JSON text <code>source</code> and returns the * complete data structure as a result. */ @@ -240,7 +240,7 @@ public class Parser extends RubyObject { /** * <code>Parser#source()</code> - * + * * <p>Returns a copy of the current <code>source</code> string, that was * used to construct this Parser. */ @@ -268,7 +268,7 @@ public class Parser extends RubyObject { /** * A string parsing session. - * + * * <p>Once a ParserSession is instantiated, the source string should not * change until the parsing is complete. The ParserSession object assumes * the source {@link RubyString} is still associated to its original @@ -308,11 +308,11 @@ public class Parser extends RubyObject { return context.getRuntime(); } - + // line 335 "Parser.rl" - + // line 317 "Parser.java" private static byte[] init__JSON_value_actions_0() { @@ -434,14 +434,14 @@ static final int JSON_value_en_main = 1; int cs = EVIL; IRubyObject result = null; - + // line 439 "Parser.java" { cs = JSON_value_start; } // line 448 "Parser.rl" - + // line 446 "Parser.java" { int _klen; @@ -675,7 +675,7 @@ case 5: } } - + // line 680 "Parser.java" private static byte[] init__JSON_integer_actions_0() { @@ -781,7 +781,7 @@ static final int JSON_integer_en_main = 1; ParserResult parseInteger(int p, int pe) { int cs = EVIL; - + // line 786 "Parser.java" { cs = JSON_integer_start; @@ -789,7 +789,7 @@ static final int JSON_integer_en_main = 1; // line 474 "Parser.rl" int memo = p; - + // line 794 "Parser.java" { int _klen; @@ -911,7 +911,7 @@ case 5: return new ParserResult(number, p + 1); } - + // line 916 "Parser.java" private static byte[] init__JSON_float_actions_0() { @@ -1020,7 +1020,7 @@ static final int JSON_float_en_main = 1; ParserResult parseFloat(int p, int pe) { int cs = EVIL; - + // line 1025 "Parser.java" { cs = JSON_float_start; @@ -1028,7 +1028,7 @@ static final int JSON_float_en_main = 1; // line 510 "Parser.rl" int memo = p; - + // line 1033 "Parser.java" { int _klen; @@ -1150,7 +1150,7 @@ case 5: return new ParserResult(number, p + 1); } - + // line 1155 "Parser.java" private static byte[] init__JSON_string_actions_0() { @@ -1260,7 +1260,7 @@ static final int JSON_string_en_main = 1; int cs = EVIL; IRubyObject result = null; - + // line 1265 "Parser.java" { cs = JSON_string_start; @@ -1268,7 +1268,7 @@ static final int JSON_string_en_main = 1; // line 563 "Parser.rl" int memo = p; - + // line 1273 "Parser.java" { int _klen; @@ -1408,7 +1408,7 @@ case 5: } }); } catch (JumpException e) { } - if (memoArray[1] != null) { + if (memoArray[1] != null) { RubyClass klass = (RubyClass) memoArray[1]; if (klass.respondsTo("json_creatable?") && klass.callMethod(context, "json_creatable?").isTrue()) { @@ -1425,7 +1425,7 @@ case 5: } } - + // line 1430 "Parser.java" private static byte[] init__JSON_array_actions_0() { @@ -1556,14 +1556,14 @@ static final int JSON_array_en_main = 1; (RubyArray)parser.arrayClass.newInstance(context, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); - + // line 1561 "Parser.java" { cs = JSON_array_start; } // line 652 "Parser.rl" - + // line 1568 "Parser.java" { int _klen; @@ -1697,7 +1697,7 @@ case 5: } } - + // line 1702 "Parser.java" private static byte[] init__JSON_object_actions_0() { @@ -1839,14 +1839,14 @@ static final int JSON_object_en_main = 1; (RubyHash)parser.objectClass.newInstance(context, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK); - + // line 1844 "Parser.java" { cs = JSON_object_start; } // line 731 "Parser.rl" - + // line 1851 "Parser.java" { int _klen; @@ -2016,7 +2016,7 @@ case 5: return new ParserResult(returnedResult, p + 1); } - + // line 2021 "Parser.java" private static byte[] init__JSON_actions_0() { @@ -2129,7 +2129,7 @@ static final int JSON_en_main = 1; int p, pe; IRubyObject result = null; - + // line 2134 "Parser.java" { cs = JSON_start; @@ -2138,7 +2138,7 @@ static final int JSON_en_main = 1; // line 798 "Parser.rl" p = byteList.begin(); pe = p + byteList.length(); - + // line 2143 "Parser.java" { int _klen; diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl index 779d3f3..6b99574 100644 --- a/java/src/json/ext/Parser.rl +++ b/java/src/json/ext/Parser.rl @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ @@ -29,16 +29,16 @@ import org.jruby.util.ByteList; /** * The <code>JSON::Ext::Parser</code> class. - * + * * <p>This is the JSON parser implemented as a Java class. To use it as the * standard parser, set * <pre>JSON.parser = JSON::Ext::Parser</pre> * This is performed for you when you <code>include "json/ext"</code>. - * + * * <p>This class does not perform the actual parsing, just acts as an interface * to Ruby code. When the {@link #parse()} method is invoked, a * Parser.ParserSession object is instantiated, which handles the process. - * + * * @author mernen */ public class Parser extends RubyObject { @@ -69,7 +69,7 @@ public class Parser extends RubyObject { /** * Multiple-value return for internal parser methods. - * + * * <p>All the <code>parse<var>Stuff</var></code> methods return instances of * <code>ParserResult</code> when successful, or <code>null</code> when * there's a problem with the input data. @@ -98,18 +98,18 @@ public class Parser extends RubyObject { /** * <code>Parser.new(source, opts = {})</code> - * + * * <p>Creates a new <code>JSON::Ext::Parser</code> instance for the string * <code>source</code>. * It will be configured by the <code>opts</code> Hash. * <code>opts</code> can have the following keys: - * + * * <dl> * <dt><code>:max_nesting</code> * <dd>The maximum depth of nesting allowed in the parsed data * structures. Disable depth checking with <code>:max_nesting => false|nil|0</code>, * it defaults to 19. - * + * * <dt><code>:allow_nan</code> * <dd>If set to <code>true</code>, allow <code>NaN</code>, * <code>Infinity</code> and <code>-Infinity</code> in defiance of RFC 4627 @@ -118,15 +118,15 @@ public class Parser extends RubyObject { * <dt><code>:symbolize_names</code> * <dd>If set to <code>true</code>, returns symbols for the names (keys) in * a JSON object. Otherwise strings are returned, which is also the default. - * + * * <dt><code>:create_additions</code> * <dd>If set to <code>false</code>, the Parser doesn't create additions * even if a matchin class and <code>create_id</code> was found. This option * defaults to <code>true</code>. - * + * * <dt><code>:object_class</code> * <dd>Defaults to Hash. - * + * * <dt><code>:array_class</code> * <dd>Defaults to Array. * </dl> @@ -227,7 +227,7 @@ public class Parser extends RubyObject { /** * <code>Parser#parse()</code> - * + * * <p>Parses the current JSON text <code>source</code> and returns the * complete data structure as a result. */ @@ -238,7 +238,7 @@ public class Parser extends RubyObject { /** * <code>Parser#source()</code> - * + * * <p>Returns a copy of the current <code>source</code> string, that was * used to construct this Parser. */ @@ -266,7 +266,7 @@ public class Parser extends RubyObject { /** * A string parsing session. - * + * * <p>Once a ParserSession is instantiated, the source string should not * change until the parsing is complete. The ParserSession object assumes * the source {@link RubyString} is still associated to its original @@ -578,7 +578,7 @@ public class Parser extends RubyObject { } }); } catch (JumpException e) { } - if (memoArray[1] != null) { + if (memoArray[1] != null) { RubyClass klass = (RubyClass) memoArray[1]; if (klass.respondsTo("json_creatable?") && klass.callMethod(context, "json_creatable?").isTrue()) { diff --git a/java/src/json/ext/ParserService.java b/java/src/json/ext/ParserService.java index f2ecae1..dde8834 100644 --- a/java/src/json/ext/ParserService.java +++ b/java/src/json/ext/ParserService.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ diff --git a/java/src/json/ext/Utils.java b/java/src/json/ext/Utils.java index f52ac8d..44d6a55 100644 --- a/java/src/json/ext/Utils.java +++ b/java/src/json/ext/Utils.java @@ -1,6 +1,6 @@ /* * This code is copyrighted work by Daniel Luz <dev at mernen dot com>. - * + * * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files * for details. */ diff --git a/json.gemspec b/json.gemspec index 456715d..4aefd2a 100644 --- a/json.gemspec +++ b/json.gemspec @@ -5,21 +5,21 @@ Gem::Specification.new do |s| s.version = "1.5.4" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = [%q{Florian Frank}] - s.date = %q{2011-07-24} + s.authors = ["Florian Frank"] + s.date = %q{2011-07-27} s.description = %q{This is a JSON implementation as a Ruby extension in C.} s.email = %q{flori@ping.de} - s.executables = [%q{edit_json.rb}, %q{prettify_json.rb}] - s.extensions = [%q{ext/json/ext/parser/extconf.rb}, %q{ext/json/ext/generator/extconf.rb}] - s.extra_rdoc_files = [%q{README.rdoc}] - s.files = [%q{Gemfile.lock}, %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/json.xpm}, %q{lib/json/TrueClass.xpm}, %q{lib/json/version.rb}, %q{lib/json/Array.xpm}, %q{lib/json/add}, %q{lib/json/add/core.rb}, %q{lib/json/add/rails.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/Key.xpm}, %q{lib/json/FalseClass.xpm}, %q{lib/json/editor.rb}, %q{lib/json/Numeric.xpm}, %q{lib/json/ext}, %q{lib/json/NilClass.xpm}, %q{lib/json/String.xpm}, %q{lib/json/Hash.xpm}, %q{lib/json.rb}, %q{Gemfile}, %q{README.rdoc}, %q{json_pure.gemspec}, %q{GPL}, %q{CHANGES}, %q{bin}, %q{bin/prettify_json.rb}, %q{bin/edit_json.rb}, %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}] + s.executables = ["edit_json.rb", "prettify_json.rb"] + s.extensions = ["ext/json/ext/parser/extconf.rb", "ext/json/ext/generator/extconf.rb"] + s.extra_rdoc_files = ["README.rdoc"] + s.files = ["tests", "tests/test_json_string_matching.rb", "tests/test_json_fixtures.rb", "tests/setup_variant.rb", "tests/fixtures", "tests/fixtures/fail6.json", "tests/fixtures/fail9.json", "tests/fixtures/fail10.json", "tests/fixtures/fail24.json", "tests/fixtures/fail28.json", "tests/fixtures/fail13.json", "tests/fixtures/fail4.json", "tests/fixtures/pass3.json", "tests/fixtures/fail11.json", "tests/fixtures/fail14.json", "tests/fixtures/fail3.json", "tests/fixtures/fail12.json", "tests/fixtures/pass16.json", "tests/fixtures/pass15.json", "tests/fixtures/fail20.json", "tests/fixtures/fail8.json", "tests/fixtures/pass2.json", "tests/fixtures/fail5.json", "tests/fixtures/fail1.json", "tests/fixtures/fail25.json", "tests/fixtures/pass17.json", "tests/fixtures/fail7.json", "tests/fixtures/pass26.json", "tests/fixtures/fail21.json", "tests/fixtures/pass1.json", "tests/fixtures/fail23.json", "tests/fixtures/fail18.json", "tests/fixtures/fail2.json", "tests/fixtures/fail22.json", "tests/fixtures/fail27.json", "tests/fixtures/fail19.json", "tests/test_json_unicode.rb", "tests/test_json_addition.rb", "tests/test_json_generate.rb", "tests/test_json_encoding.rb", "tests/test_json.rb", "COPYING", "TODO", "Rakefile", "benchmarks", "benchmarks/data-p4-3GHz-ruby18", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat", "benchmarks/parser2_benchmark.rb", "benchmarks/parser_benchmark.rb", "benchmarks/generator2_benchmark.rb", "benchmarks/generator_benchmark.rb", "benchmarks/ohai.ruby", "benchmarks/data", "benchmarks/ohai.json", "lib", "lib/json", "lib/json/json.xpm", "lib/json/TrueClass.xpm", "lib/json/version.rb", "lib/json/Array.xpm", "lib/json/add", "lib/json/add/core.rb", "lib/json/common.rb", "lib/json/pure", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/ext.rb", "lib/json/pure.rb", "lib/json/Key.xpm", "lib/json/FalseClass.xpm", "lib/json/editor.rb", "lib/json/Numeric.xpm", "lib/json/ext", "lib/json/NilClass.xpm", "lib/json/String.xpm", "lib/json/Hash.xpm", "lib/json.rb", "Gemfile", "README.rdoc", "json_pure.gemspec", "GPL", "CHANGES", "bin", "bin/prettify_json.rb", "bin/edit_json.rb", "COPYING-json-jruby", "ext", "ext/json", "ext/json/ext", "ext/json/ext/parser", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.rl", "ext/json/ext/parser/parser.c", "ext/json/ext/generator", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.h", "VERSION", "data", "data/prototype.js", "data/index.html", "data/example.json", "json.gemspec", "java", "java/src", "java/src/json", "java/src/json/ext", "java/src/json/ext/Parser.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/ParserService.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/Utils.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/GeneratorMethods.java", "java/lib", "java/lib/bytelist-1.0.6.jar", "java/lib/jcodings.jar", "diagrams", "README-json-jruby.markdown", "install.rb", "json-java.gemspec", "tools", "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"] s.homepage = %q{http://flori.github.com/json} - s.rdoc_options = [%q{--title}, %q{JSON implemention for Ruby}, %q{--main}, %q{README.rdoc}] - s.require_paths = [%q{ext/json/ext}, %q{ext}, %q{lib}] + s.rdoc_options = ["--title", "JSON implemention for Ruby", "--main", "README.rdoc"] + s.require_paths = ["ext/json/ext", "ext", "lib"] s.rubyforge_project = %q{json} - s.rubygems_version = %q{1.8.5} + s.rubygems_version = %q{1.6.2} s.summary = %q{JSON Implementation for Ruby} - 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}] + 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"] if s.respond_to? :specification_version then s.specification_version = 3 diff --git a/json_pure.gemspec b/json_pure.gemspec index 9e4c082..a33479e 100644 --- a/json_pure.gemspec +++ b/json_pure.gemspec @@ -5,20 +5,20 @@ Gem::Specification.new do |s| s.version = "1.5.4" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = [%q{Florian Frank}] - s.date = %q{2011-07-24} + s.authors = ["Florian Frank"] + s.date = %q{2011-07-27} s.description = %q{This is a JSON implementation in pure Ruby.} s.email = %q{flori@ping.de} - s.executables = [%q{edit_json.rb}, %q{prettify_json.rb}] - s.extra_rdoc_files = [%q{README.rdoc}] - s.files = [%q{Gemfile.lock}, %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/json.xpm}, %q{lib/json/TrueClass.xpm}, %q{lib/json/version.rb}, %q{lib/json/Array.xpm}, %q{lib/json/add}, %q{lib/json/add/core.rb}, %q{lib/json/add/rails.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/Key.xpm}, %q{lib/json/FalseClass.xpm}, %q{lib/json/editor.rb}, %q{lib/json/Numeric.xpm}, %q{lib/json/ext}, %q{lib/json/NilClass.xpm}, %q{lib/json/String.xpm}, %q{lib/json/Hash.xpm}, %q{lib/json.rb}, %q{Gemfile}, %q{README.rdoc}, %q{json_pure.gemspec}, %q{GPL}, %q{CHANGES}, %q{bin}, %q{bin/prettify_json.rb}, %q{bin/edit_json.rb}, %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}] + s.executables = ["edit_json.rb", "prettify_json.rb"] + s.extra_rdoc_files = ["README.rdoc"] + s.files = ["tests", "tests/test_json_string_matching.rb", "tests/test_json_fixtures.rb", "tests/setup_variant.rb", "tests/fixtures", "tests/fixtures/fail6.json", "tests/fixtures/fail9.json", "tests/fixtures/fail10.json", "tests/fixtures/fail24.json", "tests/fixtures/fail28.json", "tests/fixtures/fail13.json", "tests/fixtures/fail4.json", "tests/fixtures/pass3.json", "tests/fixtures/fail11.json", "tests/fixtures/fail14.json", "tests/fixtures/fail3.json", "tests/fixtures/fail12.json", "tests/fixtures/pass16.json", "tests/fixtures/pass15.json", "tests/fixtures/fail20.json", "tests/fixtures/fail8.json", "tests/fixtures/pass2.json", "tests/fixtures/fail5.json", "tests/fixtures/fail1.json", "tests/fixtures/fail25.json", "tests/fixtures/pass17.json", "tests/fixtures/fail7.json", "tests/fixtures/pass26.json", "tests/fixtures/fail21.json", "tests/fixtures/pass1.json", "tests/fixtures/fail23.json", "tests/fixtures/fail18.json", "tests/fixtures/fail2.json", "tests/fixtures/fail22.json", "tests/fixtures/fail27.json", "tests/fixtures/fail19.json", "tests/test_json_unicode.rb", "tests/test_json_addition.rb", "tests/test_json_generate.rb", "tests/test_json_encoding.rb", "tests/test_json.rb", "COPYING", "TODO", "Rakefile", "benchmarks", "benchmarks/data-p4-3GHz-ruby18", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkPure#parser.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkRails#parser.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_safe-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkRails#generator-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkPure#generator_fast.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkComparison.log", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_pretty-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/ParserBenchmarkYAML#parser-autocorrelation.dat", "benchmarks/data-p4-3GHz-ruby18/GeneratorBenchmarkExt#generator_safe-autocorrelation.dat", "benchmarks/parser2_benchmark.rb", "benchmarks/parser_benchmark.rb", "benchmarks/generator2_benchmark.rb", "benchmarks/generator_benchmark.rb", "benchmarks/ohai.ruby", "benchmarks/data", "benchmarks/ohai.json", "lib", "lib/json", "lib/json/json.xpm", "lib/json/TrueClass.xpm", "lib/json/version.rb", "lib/json/Array.xpm", "lib/json/add", "lib/json/add/core.rb", "lib/json/common.rb", "lib/json/pure", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/ext.rb", "lib/json/pure.rb", "lib/json/Key.xpm", "lib/json/FalseClass.xpm", "lib/json/editor.rb", "lib/json/Numeric.xpm", "lib/json/ext", "lib/json/NilClass.xpm", "lib/json/String.xpm", "lib/json/Hash.xpm", "lib/json.rb", "Gemfile", "README.rdoc", "json_pure.gemspec", "GPL", "CHANGES", "bin", "bin/prettify_json.rb", "bin/edit_json.rb", "COPYING-json-jruby", "ext", "ext/json", "ext/json/ext", "ext/json/ext/parser", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.rl", "ext/json/ext/parser/parser.c", "ext/json/ext/generator", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.h", "VERSION", "data", "data/prototype.js", "data/index.html", "data/example.json", "json.gemspec", "java", "java/src", "java/src/json", "java/src/json/ext", "java/src/json/ext/Parser.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/ParserService.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/Utils.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/GeneratorMethods.java", "java/lib", "java/lib/bytelist-1.0.6.jar", "java/lib/jcodings.jar", "diagrams", "README-json-jruby.markdown", "install.rb", "json-java.gemspec", "tools", "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"] s.homepage = %q{http://flori.github.com/json} - s.rdoc_options = [%q{--title}, %q{JSON implemention for ruby}, %q{--main}, %q{README.rdoc}] - s.require_paths = [%q{lib}] + s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.rdoc"] + s.require_paths = ["lib"] s.rubyforge_project = %q{json} - s.rubygems_version = %q{1.8.5} + s.rubygems_version = %q{1.6.2} s.summary = %q{JSON Implementation for Ruby} - 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}] + 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"] if s.respond_to? :specification_version then s.specification_version = 3 diff --git a/lib/json/common.rb b/lib/json/common.rb index 1a5f048..1330acc 100644 --- a/lib/json/common.rb +++ b/lib/json/common.rb @@ -198,7 +198,11 @@ module JSON # amount of sanity checks, and the pretty_generate method for some # defaults for a pretty output. def generate(obj, opts = nil) - state = SAFE_STATE_PROTOTYPE.dup + if State === opts + state, opts = opts, nil + else + state = SAFE_STATE_PROTOTYPE.dup + end if opts if opts.respond_to? :to_hash opts = opts.to_hash @@ -225,7 +229,11 @@ module JSON # *WARNING*: Be careful not to pass any Ruby data structures with circles as # _obj_ argument, because this will cause JSON to go into an infinite loop. def fast_generate(obj, opts = nil) - state = FAST_STATE_PROTOTYPE.dup + if State === opts + state, opts = opts, nil + else + state = FAST_STATE_PROTOTYPE.dup + end if opts if opts.respond_to? :to_hash opts = opts.to_hash @@ -252,7 +260,11 @@ module JSON # The _opts_ argument can be used to configure the generator, see the # generate method for a more detailed explanation. def pretty_generate(obj, opts = nil) - state = PRETTY_STATE_PROTOTYPE.dup + if State === opts + state, opts = opts, nil + else + state = PRETTY_STATE_PROTOTYPE.dup + end if opts if opts.respond_to? :to_hash opts = opts.to_hash diff --git a/lib/json/pure/generator.rb b/lib/json/pure/generator.rb index 3687e30..59df74d 100644 --- a/lib/json/pure/generator.rb +++ b/lib/json/pure/generator.rb @@ -141,6 +141,7 @@ module JSON @array_nl = '' @allow_nan = false @ascii_only = false + @quirks_mode = false configure opts end @@ -165,6 +166,10 @@ module JSON # the generated JSON, max_nesting = 0 if no maximum is checked. attr_accessor :max_nesting + # If this attribute is set to true, quirks mode is enabled, otherwise + # it's disabled. + attr_accessor :quirks_mode + # This integer returns the current depth data structure nesting in the # generated JSON. attr_accessor :depth @@ -188,10 +193,17 @@ module JSON @allow_nan end + # Returns true, if only ASCII characters should be generated. Otherwise + # returns false. def ascii_only? @ascii_only end + # Returns true, if quirks mode is enabled. Otherwise returns false. + def quirks_mode? + @quirks_mode + end + # Configure this State instance with the Hash _opts_, and return # itself. def configure(opts) @@ -203,6 +215,7 @@ module JSON @allow_nan = !!opts[:allow_nan] if opts.key?(:allow_nan) @ascii_only = opts[:ascii_only] if opts.key?(:ascii_only) @depth = opts[:depth] || 0 + @quirks_mode = opts[:quirks_mode] if opts.key?(:quirks_mode) if !opts.key?(:max_nesting) # defaults to 19 @max_nesting = 19 elsif opts[:max_nesting] @@ -218,7 +231,7 @@ module JSON # passed to the configure method. def to_h result = {} - for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only depth] + for iv in %w[indent space space_before object_nl array_nl allow_nan max_nesting ascii_only quirks_mode depth] result[iv.intern] = instance_variable_get("@#{iv}") end result @@ -229,7 +242,7 @@ module JSON # GeneratorError exception. def generate(obj) result = obj.to_json(self) - if result !~ /\A\s*(?:\[.*\]|\{.*\})\s*\Z/m + if !@quirks_mode && result !~ /\A\s*(?:\[.*\]|\{.*\})\s*\Z/m raise GeneratorError, "only generation of JSON objects or arrays allowed" end result diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb index 9b0cff4..dc1450a 100755 --- a/tests/test_json_generate.rb +++ b/tests/test_json_generate.rb @@ -50,6 +50,7 @@ EOT parsed_json = parse(json) assert_equal({"1"=>2}, parsed_json) assert_raise(GeneratorError) { generate(666) } + assert_equal '666', generate(666, :quirks_mode => true) end def test_generate_pretty @@ -67,6 +68,7 @@ EOT parsed_json = parse(json) assert_equal({"1"=>2}, parsed_json) assert_raise(GeneratorError) { pretty_generate(666) } + assert_equal '666', pretty_generate(666, :quirks_mode => true) end def test_fast_generate @@ -79,9 +81,24 @@ EOT parsed_json = parse(json) assert_equal({"1"=>2}, parsed_json) assert_raise(GeneratorError) { fast_generate(666) } + assert_equal '666', fast_generate(666, :quirks_mode => true) end - + def test_own_state + state = State.new + json = generate(@hash, state) + assert_equal(JSON.parse(@json2), JSON.parse(json)) + parsed_json = parse(json) + assert_equal(@hash, parsed_json) + json = generate({1=>2}, state) + assert_equal('{"1":2}', json) + parsed_json = parse(json) + assert_equal({"1"=>2}, parsed_json) + assert_raise(GeneratorError) { generate(666, state) } + state.quirks_mode = true + assert state.quirks_mode? + assert_equal '666', generate(666, state) + end def test_states json = generate({1=>2}, nil) @@ -107,6 +124,7 @@ EOT :allow_nan => false, :array_nl => "\n", :ascii_only => false, + :quirks_mode => false, :depth => 0, :indent => " ", :max_nesting => 19, @@ -122,6 +140,7 @@ EOT :allow_nan => false, :array_nl => "", :ascii_only => false, + :quirks_mode => false, :depth => 0, :indent => "", :max_nesting => 19, @@ -137,6 +156,7 @@ EOT :allow_nan => false, :array_nl => "", :ascii_only => false, + :quirks_mode => false, :depth => 0, :indent => "", :max_nesting => 0, |