1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/json/lib/json/common.rb: don't use iconv on 1.9.

patched by Shota Fukumori [ruby-core:33164]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30004 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-12-01 16:26:15 +00:00
parent 4a84c27e3e
commit 521876c373
3 changed files with 22 additions and 10 deletions

View file

@ -1,3 +1,8 @@
Thu Dec 2 01:24:39 2010 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json/lib/json/common.rb: don't use iconv on 1.9.
patched by Shota Fukumori [ruby-core:33164]
Thu Dec 2 01:02:03 2010 NARUSE, Yui <naruse@ruby-lang.org>
* ext/json: Update github/flori/json from 1.4.2+ to

View file

@ -1,5 +1,4 @@
require 'json/version'
require 'iconv'
module JSON
class << self
@ -342,8 +341,15 @@ module JSON
end
# Shortuct for iconv.
def self.iconv(to, from, string)
Iconv.iconv(to, from, string).first
if String.method_defined?(:encode)
def self.iconv(to, from, string)
string.encode(to, from)
end
else
require 'iconv'
def self.iconv(to, from, string)
Iconv.iconv(to, from, string).first
end
end
end

View file

@ -7,7 +7,6 @@ when 'pure' then require 'json/pure'
when 'ext' then require 'json/ext'
else require 'json'
end
require 'iconv'
class TC_JSONEncoding < Test::Unit::TestCase
include JSON
@ -15,19 +14,21 @@ class TC_JSONEncoding < Test::Unit::TestCase
def setup
@utf_8 = '["© ≠ €!"]'
@parsed = [ "© ≠ €!" ]
@utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
@generated = '["\u00a9 \u2260 \u20ac!"]'
if defined?(::Encoding)
if String.method_defined?(:encode)
@utf_16_data = [@parsed.first.encode('utf-16be', 'utf-8')]
@utf_8_ascii_8bit = @utf_8.dup.force_encoding(Encoding::ASCII_8BIT)
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
@utf_16be = @utf_8.encode('utf-16be', 'utf-8')
@utf_16be_ascii_8bit = @utf_16be.dup.force_encoding(Encoding::ASCII_8BIT)
@utf_16le, = Iconv.iconv('utf-16le', 'utf-8', @utf_8)
@utf_16le = @utf_8.encode('utf-16le', 'utf-8')
@utf_16le_ascii_8bit = @utf_16le.dup.force_encoding(Encoding::ASCII_8BIT)
@utf_32be, = Iconv.iconv('utf-32be', 'utf-8', @utf_8)
@utf_32be = @utf_8.encode('utf-32be', 'utf-8')
@utf_32be_ascii_8bit = @utf_32be.dup.force_encoding(Encoding::ASCII_8BIT)
@utf_32le, = Iconv.iconv('utf-32le', 'utf-8', @utf_8)
@utf_32le = @utf_8.encode('utf-32le', 'utf-8')
@utf_32le_ascii_8bit = @utf_32le.dup.force_encoding(Encoding::ASCII_8BIT)
else
require 'iconv'
@utf_16_data = Iconv.iconv('utf-16be', 'utf-8', @parsed.first)
@utf_8_ascii_8bit = @utf_8.dup
@utf_16be, = Iconv.iconv('utf-16be', 'utf-8', @utf_8)
@utf_16be_ascii_8bit = @utf_16be.dup