summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-13 07:18:58 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-13 07:18:58 +0000
commite9e9ec43f5f601782fe841d7364723d6e4975fa7 (patch)
tree9242426c4ca5551a3dd5882362885206c75f9d93 /ext
parente52527a4f92e5e575ebcc7d9fe83247cae6e0ffe (diff)
* ext/json: Import JSON 1.5.5.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/json/lib/json/add/core.rb9
-rw-r--r--ext/json/lib/json/common.rb17
-rw-r--r--ext/json/lib/json/version.rb2
-rw-r--r--ext/json/parser/parser.c36
-rw-r--r--ext/json/parser/parser.rl5
5 files changed, 41 insertions, 28 deletions
diff --git a/ext/json/lib/json/add/core.rb b/ext/json/lib/json/add/core.rb
index 1ae00d01a5..01b8e0412b 100644
--- a/ext/json/lib/json/add/core.rb
+++ b/ext/json/lib/json/add/core.rb
@@ -36,8 +36,8 @@ class Time
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'))
+ if instance_methods.include?(:tv_nsec)
+ at(object['s'], Rational(object['n'], 1000))
else
at(object['s'], object['n'] / 1000)
end
@@ -46,10 +46,13 @@ class Time
# Returns a hash, that will be turned into a JSON object and represent this
# object.
def as_json(*)
+ nanoseconds = [ tv_usec * 1000 ]
+ respond_to?(:tv_nsec) and nanoseconds << tv_nsec
+ nanoseconds = nanoseconds.max
{
JSON.create_id => self.class.name,
's' => tv_sec,
- 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
+ 'n' => nanoseconds,
}
end
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index 43e249c954..9ad1fab545 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -141,7 +141,7 @@ module JSON
# the default.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matching class and create_id was found. This option
- # defaults to true.
+ # defaults to false.
# * *object_class*: Defaults to Hash
# * *array_class*: Defaults to Array
def parse(source, opts = {})
@@ -162,7 +162,7 @@ module JSON
# to true.
# * *create_additions*: If set to false, the Parser doesn't create
# additions even if a matching class and create_id was found. This option
- # defaults to true.
+ # defaults to false.
def parse!(source, opts = {})
opts = {
:max_nesting => false,
@@ -287,11 +287,18 @@ module JSON
# 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
# 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.
+ # Ruby object as an argument recursively in depth first order. To modify the
+ # default options pass in the optional _options_ argument as well.
#
# This method is part of the implementation of the load/dump interface of
# Marshal and YAML.
- def load(source, proc = nil)
+ def load(source, proc = nil, options = {})
+ load_default_options = {
+ :max_nesting => false,
+ :allow_nan => true,
+ :create_additions => false
+ }
+ opts = load_default_options.merge options
if source.respond_to? :to_str
source = source.to_str
elsif source.respond_to? :to_io
@@ -299,7 +306,7 @@ module JSON
else
source = source.read
end
- result = parse(source, :max_nesting => false, :allow_nan => true)
+ result = parse(source, opts)
recurse_proc(result, &proc) if proc
result
end
diff --git a/ext/json/lib/json/version.rb b/ext/json/lib/json/version.rb
index 2175ac0f90..baacdc9124 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.5.4'
+ VERSION = '1.5.5'
VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index c0ec9ec2b0..8a321a8839 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -1676,7 +1676,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
if (option_given_p(opts, tmp)) {
json->create_additions = RTEST(rb_hash_aref(opts, tmp));
} else {
- json->create_additions = 1;
+ json->create_additions = 0;
}
tmp = ID2SYM(i_create_id);
if (option_given_p(opts, tmp)) {
@@ -1723,7 +1723,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
}
-#line 1719 "parser.c"
+#line 1722 "parser.c"
static const int JSON_start = 1;
static const int JSON_first_final = 10;
static const int JSON_error = 0;
@@ -1731,7 +1731,7 @@ static const int JSON_error = 0;
static const int JSON_en_main = 1;
-#line 726 "parser.rl"
+#line 729 "parser.rl"
static VALUE cParser_parse_strict(VALUE self)
@@ -1742,16 +1742,16 @@ static VALUE cParser_parse_strict(VALUE self)
GET_PARSER;
-#line 1738 "parser.c"
+#line 1741 "parser.c"
{
cs = JSON_start;
}
-#line 736 "parser.rl"
+#line 739 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1747 "parser.c"
+#line 1750 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1807,7 +1807,7 @@ case 5:
goto st1;
goto st5;
tr3:
-#line 715 "parser.rl"
+#line 718 "parser.rl"
{
char *np;
json->current_nesting = 1;
@@ -1816,7 +1816,7 @@ tr3:
}
goto st10;
tr4:
-#line 708 "parser.rl"
+#line 711 "parser.rl"
{
char *np;
json->current_nesting = 1;
@@ -1828,7 +1828,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1824 "parser.c"
+#line 1827 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1885,7 +1885,7 @@ case 9:
_out: {}
}
-#line 739 "parser.rl"
+#line 742 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -1897,7 +1897,7 @@ case 9:
-#line 1893 "parser.c"
+#line 1896 "parser.c"
static const int JSON_quirks_mode_start = 1;
static const int JSON_quirks_mode_first_final = 10;
static const int JSON_quirks_mode_error = 0;
@@ -1905,7 +1905,7 @@ static const int JSON_quirks_mode_error = 0;
static const int JSON_quirks_mode_en_main = 1;
-#line 764 "parser.rl"
+#line 767 "parser.rl"
static VALUE cParser_parse_quirks_mode(VALUE self)
@@ -1916,16 +1916,16 @@ static VALUE cParser_parse_quirks_mode(VALUE self)
GET_PARSER;
-#line 1912 "parser.c"
+#line 1915 "parser.c"
{
cs = JSON_quirks_mode_start;
}
-#line 774 "parser.rl"
+#line 777 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1921 "parser.c"
+#line 1924 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1959,7 +1959,7 @@ st0:
cs = 0;
goto _out;
tr2:
-#line 756 "parser.rl"
+#line 759 "parser.rl"
{
char *np = JSON_parse_value(json, p, pe, &result);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1969,7 +1969,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1965 "parser.c"
+#line 1968 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -2058,7 +2058,7 @@ case 9:
_out: {}
}
-#line 777 "parser.rl"
+#line 780 "parser.rl"
if (cs >= JSON_quirks_mode_first_final && p == pe) {
return result;
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index dcb5d2db6f..fe6427a649 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -607,6 +607,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)
{
@@ -657,7 +660,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
if (option_given_p(opts, tmp)) {
json->create_additions = RTEST(rb_hash_aref(opts, tmp));
} else {
- json->create_additions = 1;
+ json->create_additions = 0;
}
tmp = ID2SYM(i_create_id);
if (option_given_p(opts, tmp)) {