iconv 0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/BSDL +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +56 -0
- data/README.md +75 -0
- data/Rakefile +38 -0
- data/ext/iconv/depend +2 -0
- data/ext/iconv/extconf.rb +5 -2
- data/ext/iconv/iconv.c +578 -273
- data/iconv.gemspec +20 -0
- data/lib/iconv/version.rb +3 -0
- data/lib/iconv.rb +6 -0
- data/test/test_basic.rb +59 -0
- data/test/test_option.rb +43 -0
- data/test/test_partial.rb +41 -0
- data/test/utils.rb +23 -0
- metadata +46 -46
data/iconv.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iconv/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "iconv"
|
8
|
+
gem.version = Iconv::VERSION
|
9
|
+
gem.authors = ["NARUSE, Yui"]
|
10
|
+
gem.email = ["naruse@airemix.jp"]
|
11
|
+
gem.description = %q{iconv wrapper library}
|
12
|
+
gem.summary = %q{iconv wrapper library}
|
13
|
+
gem.homepage = "https://github.com/nurse/iconv"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.extensions = ['ext/iconv/extconf.rb']
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
end
|
data/lib/iconv.rb
ADDED
data/test/test_basic.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative "utils.rb"
|
2
|
+
|
3
|
+
class TestIconv::Basic < TestIconv
|
4
|
+
def test_euc2sjis
|
5
|
+
iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
|
6
|
+
str = iconv.iconv(EUCJ_STR)
|
7
|
+
str << iconv.iconv(nil)
|
8
|
+
assert_equal(SJIS_STR, str)
|
9
|
+
iconv.close
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_close
|
13
|
+
iconv = Iconv.new('Shift_JIS', 'EUC-JP')
|
14
|
+
output = ""
|
15
|
+
begin
|
16
|
+
output += iconv.iconv(EUCJ_STR)
|
17
|
+
output += iconv.iconv(nil)
|
18
|
+
ensure
|
19
|
+
assert_respond_to(iconv, :close)
|
20
|
+
assert_equal("", iconv.close)
|
21
|
+
assert_equal(SJIS_STR, output)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_open_without_block
|
26
|
+
assert_respond_to(Iconv, :open)
|
27
|
+
iconv = Iconv.open('SHIFT_JIS', 'EUC-JP')
|
28
|
+
str = iconv.iconv(EUCJ_STR)
|
29
|
+
str << iconv.iconv(nil)
|
30
|
+
assert_equal(SJIS_STR, str )
|
31
|
+
iconv.close
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_open_with_block
|
35
|
+
input = "#{EUCJ_STR}\n"*2
|
36
|
+
output = ""
|
37
|
+
Iconv.open("Shift_JIS", "EUC-JP") do |cd|
|
38
|
+
input.each_line do |s|
|
39
|
+
output << cd.iconv(s)
|
40
|
+
end
|
41
|
+
output << cd.iconv(nil)
|
42
|
+
end
|
43
|
+
assert_equal("#{SJIS_STR}\n"*2, output)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_invalid_arguments
|
47
|
+
assert_raise(TypeError) { Iconv.new(nil, 'Shift_JIS') }
|
48
|
+
assert_raise(TypeError) { Iconv.new('Shift_JIS', nil) }
|
49
|
+
assert_raise(TypeError) { Iconv.open(nil, 'Shift_JIS') }
|
50
|
+
assert_raise(TypeError) { Iconv.open('Shift_JIS', nil) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_unknown_encoding
|
54
|
+
assert_raise(Iconv::InvalidEncoding) { Iconv.iconv("utf-8", "X-UKNOWN", "heh") }
|
55
|
+
assert_raise(Iconv::InvalidEncoding, '[ruby-dev:39487]') {
|
56
|
+
Iconv.iconv("X-UNKNOWN-1", "X-UNKNOWN-2") {break}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
data/test/test_option.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative "utils.rb"
|
2
|
+
|
3
|
+
class TestIconv::Option < TestIconv
|
4
|
+
def test_ignore_option
|
5
|
+
begin
|
6
|
+
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP')
|
7
|
+
iconv.transliterate?
|
8
|
+
rescue NotImplementedError
|
9
|
+
return
|
10
|
+
end
|
11
|
+
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
|
12
|
+
str = iconv.iconv(EUCJ_STR)
|
13
|
+
str << iconv.iconv(nil)
|
14
|
+
assert_equal(SJIS_STR, str)
|
15
|
+
iconv.close
|
16
|
+
|
17
|
+
iconv = Iconv.new('SHIFT_JIS//IGNORE', 'EUC-JP//ignore')
|
18
|
+
str = iconv.iconv(EUCJ_STR)
|
19
|
+
str << iconv.iconv(nil)
|
20
|
+
assert_equal(SJIS_STR, str)
|
21
|
+
iconv.close
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_translit_option
|
25
|
+
begin
|
26
|
+
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP')
|
27
|
+
iconv.transliterate?
|
28
|
+
rescue NotImplementedError
|
29
|
+
return
|
30
|
+
end
|
31
|
+
iconv = Iconv.new('SHIFT_JIS', 'EUC-JP//ignore')
|
32
|
+
str = iconv.iconv(EUCJ_STR)
|
33
|
+
str << iconv.iconv(nil)
|
34
|
+
assert_equal(SJIS_STR, str)
|
35
|
+
iconv.close
|
36
|
+
|
37
|
+
iconv = Iconv.new('SHIFT_JIS//TRANSLIT', 'EUC-JP//translit//ignore')
|
38
|
+
str = iconv.iconv(EUCJ_STR)
|
39
|
+
str << iconv.iconv(nil)
|
40
|
+
assert_equal(SJIS_STR, str)
|
41
|
+
iconv.close
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "utils.rb"
|
2
|
+
|
3
|
+
class TestIconv::Partial < TestIconv
|
4
|
+
def test_partial_ascii
|
5
|
+
c = Iconv.open(ASCII, ASCII)
|
6
|
+
ref = '[ruby-core:17092]'
|
7
|
+
rescue
|
8
|
+
return
|
9
|
+
else
|
10
|
+
assert_equal("abc", c.iconv("abc"))
|
11
|
+
assert_equal("c", c.iconv("abc", 2), "#{ref}: with start")
|
12
|
+
assert_equal("c", c.iconv("abc", 2, 1), "#{ref}: with start, length")
|
13
|
+
assert_equal("c", c.iconv("abc", 2, 5), "#{ref}: with start, longer length")
|
14
|
+
assert_equal("bc", c.iconv("abc", -2), "#{ref}: with nagative start")
|
15
|
+
assert_equal("b", c.iconv("abc", -2, 1), "#{ref}: with nagative start, length")
|
16
|
+
assert_equal("bc", c.iconv("abc", -2, 5), "#{ref}: with nagative start, longer length")
|
17
|
+
assert_equal("", c.iconv("abc", 5), "#{ref}: with OOB")
|
18
|
+
assert_equal("", c.iconv("abc", 5, 2), "#{ref}: with OOB, length")
|
19
|
+
ensure
|
20
|
+
c.close if c
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_partial_euc2sjis
|
24
|
+
c = Iconv.open('SHIFT_JIS', 'EUC-JP')
|
25
|
+
rescue
|
26
|
+
return
|
27
|
+
else
|
28
|
+
assert_equal(SJIS_STR[0, 2], c.iconv(EUCJ_STR, 0, 2))
|
29
|
+
assert_equal(SJIS_STR, c.iconv(EUCJ_STR, 0, 20))
|
30
|
+
assert_equal(SJIS_STR[2..-1], c.iconv(EUCJ_STR, 2))
|
31
|
+
assert_equal(SJIS_STR[2, 2], c.iconv(EUCJ_STR, 2, 2))
|
32
|
+
assert_equal(SJIS_STR[2..-1], c.iconv(EUCJ_STR, 2, 20))
|
33
|
+
assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4))
|
34
|
+
assert_equal(SJIS_STR[-4, 2], c.iconv(EUCJ_STR, -4, 2))
|
35
|
+
assert_equal(SJIS_STR[-4..-1], c.iconv(EUCJ_STR, -4, 20))
|
36
|
+
assert_equal("", c.iconv(EUCJ_STR, 20))
|
37
|
+
assert_equal("", c.iconv(EUCJ_STR, 20, 2))
|
38
|
+
ensure
|
39
|
+
c.close
|
40
|
+
end
|
41
|
+
end
|
data/test/utils.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
gem 'iconv'
|
2
|
+
require 'iconv'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class TestIconv < ::Test::Unit::TestCase
|
6
|
+
if defined?(::Encoding) and String.method_defined?(:force_encoding)
|
7
|
+
def self.encode(str, enc)
|
8
|
+
str.force_encoding(enc)
|
9
|
+
end
|
10
|
+
else
|
11
|
+
def self.encode(str, enc)
|
12
|
+
str
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def default_test
|
17
|
+
self.class == TestIconv or super
|
18
|
+
end
|
19
|
+
|
20
|
+
ASCII = "ascii"
|
21
|
+
EUCJ_STR = encode("\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa", "EUC-JP").freeze
|
22
|
+
SJIS_STR = encode("\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8", "Shift_JIS").freeze
|
23
|
+
end if defined?(::Iconv)
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: iconv
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
version: "0.1"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
12
|
-
-
|
7
|
+
authors:
|
8
|
+
- NARUSE, Yui
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-08-19 00:00:00 +04:00
|
18
|
-
default_executable:
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
description: iconv wrapper library
|
15
|
+
email:
|
16
|
+
- naruse@airemix.jp
|
23
17
|
executables: []
|
24
|
-
|
25
|
-
extensions:
|
18
|
+
extensions:
|
26
19
|
- ext/iconv/extconf.rb
|
27
20
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- BSDL
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
30
28
|
- ext/iconv/charset_alias.rb
|
29
|
+
- ext/iconv/depend
|
31
30
|
- ext/iconv/extconf.rb
|
32
31
|
- ext/iconv/iconv.c
|
33
32
|
- ext/iconv/mkwrapper.rb
|
34
|
-
|
35
|
-
|
33
|
+
- iconv.gemspec
|
34
|
+
- lib/iconv.rb
|
35
|
+
- lib/iconv/version.rb
|
36
|
+
- test/test_basic.rb
|
37
|
+
- test/test_option.rb
|
38
|
+
- test/test_partial.rb
|
39
|
+
- test/utils.rb
|
40
|
+
homepage: https://github.com/nurse/iconv
|
36
41
|
licenses: []
|
37
|
-
|
38
42
|
post_install_message:
|
39
43
|
rdoc_options: []
|
40
|
-
|
41
|
-
require_paths:
|
44
|
+
require_paths:
|
42
45
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
47
|
none: false
|
45
|
-
requirements:
|
46
|
-
- -
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
|
49
|
-
|
50
|
-
- 0
|
51
|
-
version: "0"
|
52
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
61
58
|
requirements: []
|
62
|
-
|
63
59
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
60
|
+
rubygems_version: 1.8.24
|
65
61
|
signing_key:
|
66
62
|
specification_version: 3
|
67
|
-
summary: iconv
|
68
|
-
test_files:
|
69
|
-
|
63
|
+
summary: iconv wrapper library
|
64
|
+
test_files:
|
65
|
+
- test/test_basic.rb
|
66
|
+
- test/test_option.rb
|
67
|
+
- test/test_partial.rb
|
68
|
+
- test/utils.rb
|
69
|
+
has_rdoc:
|