summaryrefslogtreecommitdiff
path: root/ext/json/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ext/json/lib')
-rw-r--r--ext/json/lib/json/add/core.rb41
-rw-r--r--ext/json/lib/json/common.rb10
-rw-r--r--ext/json/lib/json/editor.rb1
-rw-r--r--ext/json/lib/json/pure/parser.rb5
-rw-r--r--ext/json/lib/json/version.rb2
5 files changed, 36 insertions, 23 deletions
diff --git a/ext/json/lib/json/add/core.rb b/ext/json/lib/json/add/core.rb
index 630ed6e4b70..4423e7ad75a 100644
--- a/ext/json/lib/json/add/core.rb
+++ b/ext/json/lib/json/add/core.rb
@@ -9,14 +9,21 @@ require 'date'
class Time
def self.json_create(object)
- at(*object.values_at('s', 'u'))
+ if usec = object.delete('u') # used to be tv_usec -> tv_nsec
+ object['n'] = usec * 1000
+ end
+ if respond_to?(:tv_nsec)
+ at(*object.values_at('s', 'n'))
+ else
+ at(object['s'], object['n'] / 1000)
+ end
end
def to_json(*args)
{
- 'json_class' => self.class.name.to_s,
+ 'json_class' => self.class.name,
's' => tv_sec,
- 'u' => tv_usec,
+ 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
}.to_json(*args)
end
end
@@ -26,13 +33,15 @@ class Date
civil(*object.values_at('y', 'm', 'd', 'sg'))
end
+ alias start sg unless method_defined?(:start)
+
def to_json(*args)
{
- 'json_class' => self.class.name.to_s,
+ 'json_class' => self.class.name,
'y' => year,
'm' => month,
'd' => day,
- 'sg' => @sg,
+ 'sg' => start,
}.to_json(*args)
end
end
@@ -41,14 +50,20 @@ class DateTime
def self.json_create(object)
args = object.values_at('y', 'm', 'd', 'H', 'M', 'S')
of_a, of_b = object['of'].split('/')
- args << Rational(of_a.to_i, of_b.to_i)
+ if of_b and of_b != '0'
+ args << Rational(of_a.to_i, of_b.to_i)
+ else
+ args << of_a
+ end
args << object['sg']
civil(*args)
end
+ alias start sg unless method_defined?(:start)
+
def to_json(*args)
{
- 'json_class' => self.class.name.to_s,
+ 'json_class' => self.class.name,
'y' => year,
'm' => month,
'd' => day,
@@ -56,7 +71,7 @@ class DateTime
'M' => min,
'S' => sec,
'of' => offset.to_s,
- 'sg' => @sg,
+ 'sg' => start,
}.to_json(*args)
end
end
@@ -68,7 +83,7 @@ class Range
def to_json(*args)
{
- 'json_class' => self.class.name.to_s,
+ 'json_class' => self.class.name,
'a' => [ first, last, exclude_end? ]
}.to_json(*args)
end
@@ -80,8 +95,8 @@ class Struct
end
def to_json(*args)
- klass = self.class.name.to_s
- klass.empty? and raise JSON::JSONError, "Only named structs are supported!"
+ klass = self.class.name
+ klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
{
'json_class' => klass,
'v' => values,
@@ -98,7 +113,7 @@ class Exception
def to_json(*args)
{
- 'json_class' => self.class.name.to_s,
+ 'json_class' => self.class.name,
'm' => message,
'b' => backtrace,
}.to_json(*args)
@@ -112,7 +127,7 @@ class Regexp
def to_json(*)
{
- 'json_class' => self.class.name.to_s,
+ 'json_class' => self.class.name,
'o' => options,
's' => source,
}.to_json
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index 7bc5ae06561..499fcc0dae1 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -2,7 +2,7 @@ require 'json/version'
module JSON
class << self
- # If _object_ is string like parse the string and return the parsed result
+ # If _object_ is string-like parse the string and return the parsed result
# as a Ruby data structure. Otherwise generate a JSON text from the Ruby
# data structure object and return it.
#
@@ -184,7 +184,8 @@ module JSON
end
# :stopdoc:
- # I want to deprecate these later, so I'll first be silent about them, and later delete them.
+ # I want to deprecate these later, so I'll first be silent about them, and
+ # later delete them.
alias unparse generate
module_function :unparse
# :startdoc:
@@ -238,7 +239,7 @@ module JSON
# :startdoc:
# Load a ruby data structure from a JSON _source_ and return it. A source can
- # either be a string like object, an IO like object, or an object responding
+ # either be a string-like object, an IO like object, or an object responding
# to the read method. If _proc_ was given, it will be called with any nested
# Ruby object as an argument recursively in depth first order.
#
@@ -327,7 +328,7 @@ module ::Kernel
nil
end
- # If _object_ is string like parse the string and return the parsed result as
+ # If _object_ is string-like parse the string and return the parsed result as
# a Ruby data structure. Otherwise generate a JSON text from the Ruby data
# structure object and return it.
#
@@ -351,4 +352,3 @@ class ::Class
respond_to?(:json_create)
end
end
- # vim: set et sw=2 ts=2:
diff --git a/ext/json/lib/json/editor.rb b/ext/json/lib/json/editor.rb
index 9a654006229..12a7f945918 100644
--- a/ext/json/lib/json/editor.rb
+++ b/ext/json/lib/json/editor.rb
@@ -1360,4 +1360,3 @@ module JSON
end
end
end
- # vim: set et sw=2 ts=2:
diff --git a/ext/json/lib/json/pure/parser.rb b/ext/json/lib/json/pure/parser.rb
index 39bee542690..9b30f15c07a 100644
--- a/ext/json/lib/json/pure/parser.rb
+++ b/ext/json/lib/json/pure/parser.rb
@@ -122,9 +122,8 @@ module JSON
def parse_string
if scan(STRING)
return '' if self[1].empty?
- self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do
- c = $&
- if u = UNESCAPE_MAP[c[1]]
+ self[1].gsub(%r((?:\\[\\bfnrt"/]|(?:\\u(?:[A-Fa-f\d]{4}))+|\\[\x20-\xff]))n) do |c|
+ if u = UNESCAPE_MAP[$&[1]]
u
else # \uXXXX
bytes = ''
diff --git a/ext/json/lib/json/version.rb b/ext/json/lib/json/version.rb
index 3d674ac44fa..acf8217048f 100644
--- a/ext/json/lib/json/version.rb
+++ b/ext/json/lib/json/version.rb
@@ -1,6 +1,6 @@
module JSON
# JSON version
- VERSION = '1.1.2'
+ VERSION = '1.1.3'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: