* ext/iconv: deprecated. [Feature #6322]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-04-23 13:56:11 +00:00
Родитель 82801b9113
Коммит ce2dc60216
15 изменённых файлов: 4 добавлений и 1653 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Mon Apr 23 22:56:08 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/iconv: deprecated. [Feature #6322]
Mon Apr 23 22:07:00 2012 Tanaka Akira <akr@fsij.org>
* test/socket/test_unix.rb (bound_unix_socket): make temporary

Просмотреть файл

@ -27,7 +27,6 @@ fiddle/fiddle.c
fiddle/function.c
fiddle/lib
gdbm/gdbm.c
iconv/iconv.c
io/console/console.c
io/nonblock/nonblock.c
io/wait/lib

Просмотреть файл

@ -13,7 +13,6 @@
#etc
#fcntl
#gdbm
#iconv
#io/wait
#nkf
#openssl

Просмотреть файл

@ -14,7 +14,6 @@ enumerator
etc
fcntl
gdbm
iconv
io/wait
nkf
#openssl

Просмотреть файл

@ -14,7 +14,6 @@ enumerator
etc
fcntl
#gdbm
#iconv
#io/wait
nkf
#openssl

Просмотреть файл

@ -14,7 +14,6 @@ enumerator
etc
fcntl
#gdbm
#iconv
#io/wait
nkf
#openssl

Просмотреть файл

@ -1,104 +0,0 @@
#! /usr/bin/ruby
# :stopdoc:
require 'rbconfig'
require 'optparse'
# http://www.ctan.org/get/macros/texinfo/texinfo/gnulib/lib/config.charset
# Tue, 25 Dec 2007 00:00:00 GMT
OS = RbConfig::CONFIG["target_os"]
SHELL = RbConfig::CONFIG['SHELL']
class Hash::Ordered < Hash
def [](key)
val = super and val.last
end
def []=(key, val)
ary = fetch(key) {return super(key, [self.size, key, val])} and
ary << val
end
def sort
values.sort.collect {|i, *rest| rest}
end
def each(&block)
sort.each(&block)
end
end
def charset_alias(config_charset, mapfile, target = OS)
map = Hash::Ordered.new
comments = []
open(config_charset) do |input|
input.find {|line| /^case "\$os" in/ =~ line} or break
input.find {|line|
/^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/ =~ line and
$&.split('|').any? {|pattern| File.fnmatch?(pattern.strip, target)}
} or break
input.find do |line|
case line
when /^\s*echo "(?:\$\w+\.)?([-\w*]+)\s+([-\w]+)"/
sys, can = $1, $2
can.downcase!
map[can] = sys
false
when /^\s*;;/
true
else
false
end
end
end
case target
when /linux|-gnu/
# map.delete('ascii')
when /cygwin|os2-emx/
# get rid of tilde/yen problem.
map['shift_jis'] = 'cp932'
end
st = Hash.new(0)
map = map.sort.collect do |can, *sys|
if sys.grep(/^en_us(?=.|$)/i) {break true} == true
noen = %r"^(?!en_us)\w+_\w+#{Regexp.new($')}$"i #"
sys.reject! {|s| noen =~ s}
end
sys = sys.first
st[sys] += 1
[can, sys]
end
st.delete_if {|sys, i| i == 1}.empty?
st.keys.each {|sys| st[sys] = nil}
st.default = nil
writer = proc do |f|
f.puts("require 'iconv.so'")
f.puts
f.puts(comments)
f.puts("class Iconv")
i = 0
map.each do |can, sys|
if s = st[sys]
sys = s
elsif st.key?(sys)
sys = (st[sys] = "sys#{i+=1}") + " = '#{sys}'.freeze"
else
sys = "'#{sys}'.freeze"
end
f.puts(" charset_map['#{can}'] = #{sys}")
end
f.puts("end")
end
if mapfile
open(mapfile, "w", &writer)
else
writer[STDOUT]
end
end
target = OS
opt = nil
ARGV.options do |opt2|
opt = opt2
opt.banner << " config.status map.rb"
opt.on("--target OS") {|t| target = t}
opt.parse! and (1..2) === ARGV.size
end or abort opt.to_s
charset_alias(ARGV[0], ARGV[1], target)

Просмотреть файл

@ -1,2 +0,0 @@
iconv.o: iconv.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h \
$(hdrdir)/st.h $(hdrdir)/intern.h $(hdrdir)/encoding.h

Просмотреть файл

@ -1,54 +0,0 @@
require 'mkmf'
dir_config("iconv")
conf = File.exist?(File.join($srcdir, "config.charset"))
conf = with_config("config-charset", enable_config("config-charset", conf))
if have_func("iconv", "iconv.h") or
have_library("iconv", "iconv", "iconv.h")
check_signedness("size_t")
if checking_for("const of iconv() 2nd argument") do
create_tmpsrc(cpp_include("iconv.h") + "---> iconv(cd,0,0,0,0) <---")
src = xpopen(cpp_command("")) {|f|f.read}
if !(func = src[/^--->\s*(\w+).*\s*<---/, 1])
Logging::message "iconv function name not found"
false
elsif !(second = src[%r"\b#{func}\s*\(.*?,(.*?),.*?\)\s*;"m, 1])
Logging::message "prototype for #{func}() not found"
false
else
Logging::message $&+"\n"
/\bconst\b/ =~ second
end
end
$defs.push('-DICONV_INPTR_CONST')
end
have_func("iconvlist", "iconv.h")
have_func("__iconv_free_list", "iconv.h")
if conf
prefix = '$(srcdir)'
prefix = $nmake ? "{#{prefix}}" : "#{prefix}/"
if $extout
wrapper = "$(RUBYARCHDIR)/iconv.rb"
else
wrapper = "./iconv.rb"
$INSTALLFILES = [[wrapper, "$(RUBYARCHDIR)"]]
end
if String === conf
require 'uri'
scheme = URI.parse(conf).scheme
else
conf = "$(srcdir)/config.charset"
end
$cleanfiles << wrapper
end
create_makefile("iconv")
if conf
open("Makefile", "a") do |mf|
mf.print("\nall: #{wrapper}\n\n#{wrapper}: #{prefix}charset_alias.rb")
mf.print(" ", conf) unless scheme
mf.print("\n\t$(RUBY) $(srcdir)/charset_alias.rb #{conf} $@\n")
end
end
end

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,53 +0,0 @@
#! /usr/bin/ruby
require 'rbconfig'
require 'optparse'
# http://www.ctan.org/get/macros/texinfo/texinfo/gnulib/lib/config.charset
# Tue, 25 Dec 2007 00:00:00 GMT
HEADER = <<SRC
require 'iconv.so'
class Iconv
case RUBY_PLATFORM
SRC
def charset_alias(config_charset, mapfile = nil)
found = nil
src = [HEADER]
open(config_charset) do |input|
input.find {|line| /^case "\$os" in/ =~ line} or return
input.each do |line|
case line
when /^\s*([-\w\*]+(?:\s*\|\s*[-\w\*]+)*)(?=\))/
(s = " when ") << $&.split('|').collect {|targ|
targ.strip!
tail = targ.chomp!("*") ? '' : '\z'
head = targ.slice!(/\A\*/) ? '' : '\A'
targ.gsub!(/\*/, '.*')
"/#{head}#{targ}#{tail}/"
}.join(", ")
src << s
found = {}
when /^\s*echo "(?:\$\w+\.)?([-\w*]+)\s+([-\w]+)"/
sys, can = $1, $2
can.downcase!
unless found[can] or (/\Aen_(?!US\z)/ =~ sys && /\ACP437\z/i =~ can)
found[can] = true
src << " charset_map['#{can}'] = '#{sys}'.freeze"
end
when /^\s*;;/
found = nil
end
end
end
src << " end" << "end"
if mapfile
open(mapfile, "wb") {|f| f.puts(*src)}
else
puts(*src)
end
end
(1..2) === ARGV.size or abort "usage: #{$0} config_charset [mapfile]"
charset_alias(*ARGV)

Просмотреть файл

@ -1,59 +0,0 @@
require File.expand_path("../utils.rb", __FILE__)
class TestIconv::Basic < TestIconv
def test_euc2sjis
iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
str = iconv.iconv(EUCJ_STR)
str << iconv.iconv(nil)
assert_equal(SJIS_STR, str)
iconv.close
end
def test_close
iconv = Iconv.new('Shift_JIS', 'EUC-JP')
output = ""
begin
output += iconv.iconv(EUCJ_STR)
output += iconv.iconv(nil)
ensure
assert_respond_to(iconv, :close)
assert_equal("", iconv.close)
assert_equal(SJIS_STR, output)
end
end
def test_open_without_block
assert_respond_to(Iconv, :open)
iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
str = iconv.iconv(EUCJ_STR)
str << iconv.iconv(nil)
assert_equal(SJIS_STR, str )
iconv.close
end
def test_open_with_block
input = "#{EUCJ_STR}\n"*2
output = ""
Iconv.open("Shift_JIS", "EUC-JP") do |cd|
input.each_line do |s|
output << cd.iconv(s)
end
output << cd.iconv(nil)
end
assert_equal("#{SJIS_STR}\n"*2, output)
end
def test_invalid_arguments
assert_raise(TypeError) { Iconv.new(nil, 'Shift_JIS') }
assert_raise(TypeError) { Iconv.new('Shift_JIS', nil) }
assert_raise(TypeError) { Iconv.open(nil, 'Shift_JIS') }
assert_raise(TypeError) { Iconv.open('Shift_JIS', nil) }
end
def test_unknown_encoding
assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
assert_raise(Iconv::InvalidEncoding, '[ruby-dev:39487]') {
Iconv.iconv("X-UNKNOWN-1", "X-UNKNOWN-2") {break}
}
end
end if defined?(TestIconv)

Просмотреть файл

@ -1,43 +0,0 @@
require File.expand_path("../utils.rb", __FILE__)
class TestIconv::Option < TestIconv
def test_ignore_option
begin
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP')
iconv.transliterate?
rescue NotImplementedError
return
end
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
str = iconv.iconv(EUCJ_STR)
str << iconv.iconv(nil)
assert_equal(SJIS_STR, str)
iconv.close
iconv = Iconv.new('SHIFT_JIS//IGNORE', 'EUC-JP//ignore')
str = iconv.iconv(EUCJ_STR)
str << iconv.iconv(nil)
assert_equal(SJIS_STR, str)
iconv.close
end
def test_translit_option
begin
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP')
iconv.transliterate?
rescue NotImplementedError
return
end
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
str = iconv.iconv(EUCJ_STR)
str << iconv.iconv(nil)
assert_equal(SJIS_STR, str)
iconv.close
iconv = Iconv.new('SHIFT_JIS//TRANSLIT', 'EUC-JP//translit//ignore')
str = iconv.iconv(EUCJ_STR)
str << iconv.iconv(nil)
assert_equal(SJIS_STR, str)
iconv.close
end
end if defined?(TestIconv)

Просмотреть файл

@ -1,41 +0,0 @@
require File.expand_path("../utils.rb", __FILE__)
class TestIconv::Partial < TestIconv
def test_partial_ascii
c = Iconv.open(ASCII, ASCII)
ref = '[ruby-core:17092]'
rescue
return
else
assert_equal("abc", c.iconv("abc"))
assert_equal("c", c.iconv("abc", 2), "#{ref}: with start")
assert_equal("c", c.iconv("abc", 2, 1), "#{ref}: with start, length")
assert_equal("c", c.iconv("abc", 2, 5), "#{ref}: with start, longer length")
assert_equal("bc", c.iconv("abc", -2), "#{ref}: with nagative start")
assert_equal("b", c.iconv("abc", -2, 1), "#{ref}: with nagative start, length")
assert_equal("bc", c.iconv("abc", -2, 5), "#{ref}: with nagative start, longer length")
assert_equal("", c.iconv("abc", 5), "#{ref}: with OOB")
assert_equal("", c.iconv("abc", 5, 2), "#{ref}: with OOB, length")
ensure
c.close if c
end
def test_partial_euc2sjis
c = Iconv.open('SHIFT_JIS', 'EUC-JP')
rescue
return
else
assert_equal(SJIS_STR[0, 2], c.iconv(EUCJ_STR, 0, 2))
assert_equal(SJIS_STR, c.iconv(EUCJ_STR, 0, 20))
assert_equal(SJIS_STR[2..-1], c.iconv(EUCJ_STR, 2))
assert_equal(SJIS_STR[2, 2], c.iconv(EUCJ_STR, 2, 2))
assert_equal(SJIS_STR[2..-1], c.iconv(EUCJ_STR, 2, 20))
assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4))
assert_equal(SJIS_STR[-4, 2], c.iconv(EUCJ_STR, -4, 2))
assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4, 20))
assert_equal("", c.iconv(EUCJ_STR, 20))
assert_equal("", c.iconv(EUCJ_STR, 20, 2))
ensure
c.close
end
end if defined?(TestIconv)

Просмотреть файл

@ -1,29 +0,0 @@
begin
verbose, $VERBOSE = $VERBOSE, nil
require 'iconv'
rescue LoadError
else
require 'test/unit'
ensure
$VERBOSE = verbose
end
class TestIconv < ::Test::Unit::TestCase
if defined?(::Encoding) and String.method_defined?(:force_encoding)
def self.encode(str, enc)
str.force_encoding(enc)
end
else
def self.encode(str, enc)
str
end
end
def default_test
self.class == TestIconv or super
end
ASCII = "ascii"
EUCJ_STR = encode("\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa", "EUC-JP").freeze
SJIS_STR = encode("\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8", "Shift_JIS").freeze
end if defined?(::Iconv)