summaryrefslogtreecommitdiff
path: root/ext/json
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-31 06:56:16 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-31 06:56:16 +0000
commitc06658feba7ae82e175bac72f241029276e715a0 (patch)
tree1f3a28b4db912f15c3b1d5e54f10bec82ee6fe34 /ext/json
parent64e0cae2741c501e8558966096b4b139d945ca82 (diff)
* ext/json: Merge json gem v1.5.4 (3dab4c5a6a97fac03dac).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33142 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json')
-rw-r--r--ext/json/generator/generator.c2
-rw-r--r--ext/json/lib/json/add/complex.rb22
-rw-r--r--ext/json/lib/json/add/core.rb36
-rw-r--r--ext/json/lib/json/add/rational.rb22
-rw-r--r--ext/json/parser/parser.c3
5 files changed, 49 insertions, 36 deletions
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index 9a90d5f..9ad037c 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -1001,6 +1001,8 @@ static VALUE cState_generate(VALUE self, VALUE obj)
* * *allow_nan*: true if NaN, Infinity, and -Infinity should be
* generated, otherwise an exception is thrown, if these values are
* encountered. This options defaults to false.
+ * * *quirks_mode*: Enables quirks_mode for parser, that is for example
+ * generating single JSON values instead of documents is possible.
*/
static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
{
diff --git a/ext/json/lib/json/add/complex.rb b/ext/json/lib/json/add/complex.rb
new file mode 100644
index 0000000..d7ebebf
--- /dev/null
+++ b/ext/json/lib/json/add/complex.rb
@@ -0,0 +1,22 @@
+unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
+ require 'json'
+end
+defined?(::Complex) or require 'complex'
+
+class Complex
+ def self.json_create(object)
+ Complex(object['r'], object['i'])
+ end
+
+ def as_json(*)
+ {
+ JSON.create_id => self.class.name,
+ 'r' => real,
+ 'i' => imag,
+ }
+ end
+
+ def to_json(*)
+ as_json.to_json
+ end
+end
diff --git a/ext/json/lib/json/add/core.rb b/ext/json/lib/json/add/core.rb
index 4624be2..1ae00d0 100644
--- a/ext/json/lib/json/add/core.rb
+++ b/ext/json/lib/json/add/core.rb
@@ -241,39 +241,3 @@ class Regexp
as_json.to_json
end
end
-
-class Rational
- def self.json_create(object)
- Rational(object['n'], object['d'])
- end
-
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'n' => numerator,
- 'd' => denominator,
- }
- end
-
- def to_json(*)
- as_json.to_json
- end
-end
-
-class Complex
- def self.json_create(object)
- Complex(object['r'], object['i'])
- end
-
- def as_json(*)
- {
- JSON.create_id => self.class.name,
- 'r' => real,
- 'i' => imag,
- }
- end
-
- def to_json(*)
- as_json.to_json
- end
-end
diff --git a/ext/json/lib/json/add/rational.rb b/ext/json/lib/json/add/rational.rb
new file mode 100644
index 0000000..867cd92
--- /dev/null
+++ b/ext/json/lib/json/add/rational.rb
@@ -0,0 +1,22 @@
+unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
+ require 'json'
+end
+defined?(::Rational) or require 'rational'
+
+class Rational
+ def self.json_create(object)
+ Rational(object['n'], object['d'])
+ end
+
+ def as_json(*)
+ {
+ JSON.create_id => self.class.name,
+ 'n' => numerator,
+ 'd' => denominator,
+ }
+ end
+
+ def to_json(*)
+ as_json.to_json
+ end
+end
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 4ea663c..d1d14c7 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -1618,6 +1618,9 @@ static VALUE convert_encoding(VALUE source)
* defaults to true.
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
+ * * *quirks_mode*: Enables quirks_mode for parser, that is for example
+ * parsing single JSON values instead of documents is possible.
+ *
*/
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{