From 37349f8b8062bc7f84a49c6649c8cc80c72046fa Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 3 Sep 2011 22:14:06 +0900 Subject: HAVE_RUBY_RE_H and HAVE_RUBY_RE_H are defined in ruby.h by default. --- ext/json/ext/generator/extconf.rb | 7 ------- ext/json/ext/generator/generator.h | 6 ++---- ext/json/ext/parser/extconf.rb | 3 --- ext/json/ext/parser/parser.h | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/ext/json/ext/generator/extconf.rb b/ext/json/ext/generator/extconf.rb index 149f22c..a9eae14 100644 --- a/ext/json/ext/generator/extconf.rb +++ b/ext/json/ext/generator/extconf.rb @@ -1,5 +1,4 @@ require 'mkmf' -require 'rbconfig' unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3') $CFLAGS << ' -O3' @@ -11,10 +10,4 @@ if CONFIG['CC'] =~ /gcc/ #end end -if RUBY_VERSION < "1.9" - have_header("re.h") -else - have_header("ruby/re.h") - have_header("ruby/encoding.h") -end create_makefile 'json/ext/generator' diff --git a/ext/json/ext/generator/generator.h b/ext/json/ext/generator/generator.h index f882ea0..1fdd351 100644 --- a/ext/json/ext/generator/generator.h +++ b/ext/json/ext/generator/generator.h @@ -7,11 +7,9 @@ #include "ruby.h" -#if HAVE_RUBY_RE_H +#ifdef HAVE_RUBY_RE_H #include "ruby/re.h" -#endif - -#if HAVE_RE_H +#else #include "re.h" #endif diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb index d2438cd..b09f122 100644 --- a/ext/json/ext/parser/extconf.rb +++ b/ext/json/ext/parser/extconf.rb @@ -1,5 +1,4 @@ require 'mkmf' -require 'rbconfig' unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3') $CFLAGS << ' -O3' @@ -11,6 +10,4 @@ if CONFIG['CC'] =~ /gcc/ #end end -have_header("re.h") -have_header("ruby/st.h") create_makefile 'json/ext/parser' diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index fc73810..da6fc5c 100644 --- a/ext/json/ext/parser/parser.h +++ b/ext/json/ext/parser/parser.h @@ -3,7 +3,7 @@ #include "ruby.h" -#if HAVE_RE_H +#ifndef HAVE_RUBY_RE_H #include "re.h" #endif -- cgit v1.2.1 From 6dc860194dfada70da5caa894630648b7bc6eedd Mon Sep 17 00:00:00 2001 From: "NARUSE, Yui" Date: Mon, 5 Sep 2011 18:06:31 +0900 Subject: Fix typo: U+0456->U+0069. --- ext/json/ext/generator/generator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c index 9ad037c..781e9e6 100644 --- a/ext/json/ext/generator/generator.c +++ b/ext/json/ext/generator/generator.c @@ -112,7 +112,7 @@ static void unicode_escape(char *buf, UTF16 character) } /* Escapes the UTF16 character and stores the result in the buffer buf, then - * the buffer buf іs appended to the FBuffer buffer. */ + * the buffer buf is appended to the FBuffer buffer. */ static void unicode_escape_to_buffer(FBuffer *buffer, char buf[6], UTF16 character) { -- cgit v1.2.1 From ac161c37c5b14adfa3d847d12195a18bb6eff30a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 3 Sep 2011 22:14:06 +0900 Subject: HAVE_RUBY_RE_H and HAVE_RUBY_RE_H are defined in ruby.h by default. --- ext/json/ext/generator/extconf.rb | 7 ------- ext/json/ext/generator/generator.h | 6 ++---- ext/json/ext/parser/extconf.rb | 3 --- ext/json/ext/parser/parser.h | 2 +- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/ext/json/ext/generator/extconf.rb b/ext/json/ext/generator/extconf.rb index 149f22c..a9eae14 100644 --- a/ext/json/ext/generator/extconf.rb +++ b/ext/json/ext/generator/extconf.rb @@ -1,5 +1,4 @@ require 'mkmf' -require 'rbconfig' unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3') $CFLAGS << ' -O3' @@ -11,10 +10,4 @@ if CONFIG['CC'] =~ /gcc/ #end end -if RUBY_VERSION < "1.9" - have_header("re.h") -else - have_header("ruby/re.h") - have_header("ruby/encoding.h") -end create_makefile 'json/ext/generator' diff --git a/ext/json/ext/generator/generator.h b/ext/json/ext/generator/generator.h index f882ea0..1fdd351 100644 --- a/ext/json/ext/generator/generator.h +++ b/ext/json/ext/generator/generator.h @@ -7,11 +7,9 @@ #include "ruby.h" -#if HAVE_RUBY_RE_H +#ifdef HAVE_RUBY_RE_H #include "ruby/re.h" -#endif - -#if HAVE_RE_H +#else #include "re.h" #endif diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb index d2438cd..b09f122 100644 --- a/ext/json/ext/parser/extconf.rb +++ b/ext/json/ext/parser/extconf.rb @@ -1,5 +1,4 @@ require 'mkmf' -require 'rbconfig' unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3') $CFLAGS << ' -O3' @@ -11,6 +10,4 @@ if CONFIG['CC'] =~ /gcc/ #end end -have_header("re.h") -have_header("ruby/st.h") create_makefile 'json/ext/parser' diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index fc73810..da6fc5c 100644 --- a/ext/json/ext/parser/parser.h +++ b/ext/json/ext/parser/parser.h @@ -3,7 +3,7 @@ #include "ruby.h" -#if HAVE_RE_H +#ifndef HAVE_RUBY_RE_H #include "re.h" #endif -- cgit v1.2.1 From 5dcfa3711a14a6a027ce6b2b62d9117fb78da1b7 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Sun, 2 Oct 2011 14:48:55 +0200 Subject: Add support for BigDecimal numbers --- ext/json/ext/parser/parser.c | 3 --- lib/json/add/bigdecimal.rb | 21 +++++++++++++++++++++ tests/test_json_addition.rb | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 lib/json/add/bigdecimal.rb diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c index d1d14c7..4ea663c 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1618,9 +1618,6 @@ 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) { diff --git a/lib/json/add/bigdecimal.rb b/lib/json/add/bigdecimal.rb new file mode 100644 index 0000000..4aafe53 --- /dev/null +++ b/lib/json/add/bigdecimal.rb @@ -0,0 +1,21 @@ +unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED + require 'json' +end +defined?(::BigDecimal) or require 'bigdecimal' + +class BigDecimal + def self.json_create(object) + BigDecimal._load object['b'] + end + + def as_json(*) + { + JSON.create_id => self.class.name, + 'b' => _dump, + } + end + + def to_json(*) + as_json.to_json + end +end diff --git a/tests/test_json_addition.rb b/tests/test_json_addition.rb index 9f578a4..b9cc6d1 100755 --- a/tests/test_json_addition.rb +++ b/tests/test_json_addition.rb @@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), 'setup_variant') require 'json/add/core' require 'json/add/complex' require 'json/add/rational' +require 'json/add/bigdecimal' require 'date' class TC_JSONAddition < Test::Unit::TestCase @@ -171,4 +172,9 @@ class TC_JSONAddition < Test::Unit::TestCase assert_equal Rational(2, 9), JSON(JSON(Rational(2, 9))) assert_equal Complex(2, 9), JSON(JSON(Complex(2, 9))) end + + def test_bigdecimal + assert_equal BigDecimal('3.141', 23), JSON(JSON(BigDecimal('3.141', 23))) + assert_equal BigDecimal('3.141', 666), JSON(JSON(BigDecimal('3.141', 666))) + end end -- cgit v1.2.1