diff options
-rw-r--r-- | ext/json/ext/generator/extconf.rb | 7 | ||||
-rw-r--r-- | ext/json/ext/generator/generator.c | 2 | ||||
-rw-r--r-- | ext/json/ext/generator/generator.h | 6 | ||||
-rw-r--r-- | ext/json/ext/parser/extconf.rb | 3 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.c | 3 | ||||
-rw-r--r-- | ext/json/ext/parser/parser.h | 2 | ||||
-rw-r--r-- | lib/json/add/bigdecimal.rb | 21 | ||||
-rwxr-xr-x | tests/test_json_addition.rb | 6 |
8 files changed, 31 insertions, 19 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.c b/ext/json/ext/generator/generator.c index 44dc3fa..8d8e71e 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) { 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.c b/ext/json/ext/parser/parser.c index 8e4753a..18ee58e 100644 --- a/ext/json/ext/parser/parser.c +++ b/ext/json/ext/parser/parser.c @@ -1628,9 +1628,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/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h index fd61a79..051f79c 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 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 |