ansel_iconv 1.1.3 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +30 -0
- data/{README.markdown → README.md} +5 -7
- data/Rakefile +33 -17
- data/lib/ansel_iconv.rb +4 -617
- data/lib/ansel_iconv/character_map.rb +566 -0
- data/lib/ansel_iconv/converter.rb +48 -0
- data/lib/ansel_iconv/iconv.rb +11 -0
- data/lib/ansel_iconv/version.rb +3 -0
- metadata +27 -15
- data/History.txt +0 -25
- data/VERSION.yml +0 -5
- data/ansel_iconv.gemspec +0 -52
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
module ANSEL
|
4
|
+
class Convert
|
5
|
+
include ANSEL::CharacterMap
|
6
|
+
|
7
|
+
def initialize(to_charset = 'UTF-8')
|
8
|
+
@to_charset = to_charset
|
9
|
+
@ansi_to_utf8 = {}
|
10
|
+
@ansi_to_utf8.merge!(@@non_combining)
|
11
|
+
@ansi_to_utf8.merge!(@@combining)
|
12
|
+
end
|
13
|
+
|
14
|
+
def iconv(string)
|
15
|
+
output = ''
|
16
|
+
scanner = StringScanner.new(string)
|
17
|
+
until scanner.eos? do
|
18
|
+
byte = scanner.get_byte
|
19
|
+
char = byte.unpack('C')[0]
|
20
|
+
|
21
|
+
if char <= 0x7F
|
22
|
+
output << byte
|
23
|
+
elsif char >= 0x88 && char <= 0xC8
|
24
|
+
hex_key = char.to_s(16).upcase
|
25
|
+
output << ::Iconv.conv(@to_charset, 'UTF-16', @ansi_to_utf8.has_key?(hex_key) ? @ansi_to_utf8[hex_key] : @ansi_to_utf8['ERR'])
|
26
|
+
scanner.get_byte # ignore the next byte
|
27
|
+
elsif char >= 0xE0 && char <= 0xFB
|
28
|
+
[2, 1, 0].each do |n| # try 3 bytes, then 2 bytes, then 1 byte
|
29
|
+
bytes = [char.to_s(16).upcase]
|
30
|
+
scanner.peek(n).each_byte {|b| bytes << b.to_s(16).upcase}
|
31
|
+
hex_key = bytes.join("+")
|
32
|
+
if @ansi_to_utf8.has_key?(hex_key)
|
33
|
+
output << ::Iconv.conv(@to_charset, 'UTF-16', @ansi_to_utf8[hex_key])
|
34
|
+
n.times {scanner.get_byte}
|
35
|
+
break
|
36
|
+
end
|
37
|
+
end
|
38
|
+
else
|
39
|
+
output << ::Iconv.conv(@to_charset, 'UTF-16', @ansi_to_utf8['ERR'])
|
40
|
+
scanner.get_byte if scanner.get_byte.unpack('C')[0] >= 0xE0 # ignore the next byte
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@to_charset == 'UTF-8' ? output : ::Iconv.conv(@to_charset, 'UTF-8', output)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansel_iconv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 5
|
10
|
+
version: 1.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Keith Morrison
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-25 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
hash: 9
|
30
30
|
segments:
|
@@ -32,6 +32,14 @@ dependencies:
|
|
32
32
|
- 3
|
33
33
|
- 5
|
34
34
|
version: 2.3.5
|
35
|
+
- - <=
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
hash: 19
|
38
|
+
segments:
|
39
|
+
- 2
|
40
|
+
- 3
|
41
|
+
- 8
|
42
|
+
version: 2.3.8
|
35
43
|
type: :runtime
|
36
44
|
version_requirements: *id001
|
37
45
|
description: Convert ANSEL encoded text to any other encoding available to Iconv
|
@@ -41,14 +49,17 @@ executables: []
|
|
41
49
|
extensions: []
|
42
50
|
|
43
51
|
extra_rdoc_files:
|
44
|
-
- README.
|
52
|
+
- README.md
|
53
|
+
- CHANGELOG.md
|
45
54
|
files:
|
46
|
-
-
|
55
|
+
- CHANGELOG.md
|
47
56
|
- MIT-LICENSE
|
48
|
-
- README.markdown
|
49
57
|
- Rakefile
|
50
|
-
-
|
51
|
-
- ansel_iconv.
|
58
|
+
- README.md
|
59
|
+
- lib/ansel_iconv/character_map.rb
|
60
|
+
- lib/ansel_iconv/converter.rb
|
61
|
+
- lib/ansel_iconv/iconv.rb
|
62
|
+
- lib/ansel_iconv/version.rb
|
52
63
|
- lib/ansel_iconv.rb
|
53
64
|
- test/ansel_iconv_test.rb
|
54
65
|
- test/test_helper.rb
|
@@ -75,10 +86,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
86
|
requirements:
|
76
87
|
- - ">="
|
77
88
|
- !ruby/object:Gem::Version
|
78
|
-
hash:
|
89
|
+
hash: 27
|
79
90
|
segments:
|
91
|
+
- 1
|
92
|
+
- 3
|
80
93
|
- 0
|
81
|
-
version:
|
94
|
+
version: 1.3.0
|
82
95
|
requirements: []
|
83
96
|
|
84
97
|
rubyforge_project:
|
@@ -86,6 +99,5 @@ rubygems_version: 1.3.7
|
|
86
99
|
signing_key:
|
87
100
|
specification_version: 3
|
88
101
|
summary: Convert ANSEL encoded text
|
89
|
-
test_files:
|
90
|
-
|
91
|
-
- test/test_helper.rb
|
102
|
+
test_files: []
|
103
|
+
|
data/History.txt
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
== 1.1.3
|
2
|
-
|
3
|
-
* MIT license
|
4
|
-
|
5
|
-
== 1.1.2
|
6
|
-
|
7
|
-
* Speed up conversion
|
8
|
-
|
9
|
-
== 1.1.0
|
10
|
-
|
11
|
-
* Ruby 1.9 compatibility
|
12
|
-
|
13
|
-
== 1.0.5
|
14
|
-
|
15
|
-
* Requires activesupport 2.3.5 and works when 3.0 is installed
|
16
|
-
|
17
|
-
== 1.0.3
|
18
|
-
|
19
|
-
* Fix ActiveSupport deprecation warning
|
20
|
-
|
21
|
-
== 1.0.0
|
22
|
-
|
23
|
-
* Initial public release
|
24
|
-
|
25
|
-
|
data/VERSION.yml
DELETED
data/ansel_iconv.gemspec
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{ansel_iconv}
|
8
|
-
s.version = "1.1.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Keith Morrison"]
|
12
|
-
s.date = %q{2010-07-03}
|
13
|
-
s.description = %q{Convert ANSEL encoded text to any other encoding available to Iconv}
|
14
|
-
s.email = %q{keithm@infused.org}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.markdown"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
"History.txt",
|
20
|
-
"MIT-LICENSE",
|
21
|
-
"README.markdown",
|
22
|
-
"Rakefile",
|
23
|
-
"VERSION.yml",
|
24
|
-
"ansel_iconv.gemspec",
|
25
|
-
"lib/ansel_iconv.rb",
|
26
|
-
"test/ansel_iconv_test.rb",
|
27
|
-
"test/test_helper.rb"
|
28
|
-
]
|
29
|
-
s.homepage = %q{http://github.com/infused/ansel_iconv}
|
30
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
-
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.3.7}
|
33
|
-
s.summary = %q{Convert ANSEL encoded text}
|
34
|
-
s.test_files = [
|
35
|
-
"test/ansel_iconv_test.rb",
|
36
|
-
"test/test_helper.rb"
|
37
|
-
]
|
38
|
-
|
39
|
-
if s.respond_to? :specification_version then
|
40
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
-
s.specification_version = 3
|
42
|
-
|
43
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
-
s.add_runtime_dependency(%q<activesupport>, ["= 2.3.5"])
|
45
|
-
else
|
46
|
-
s.add_dependency(%q<activesupport>, ["= 2.3.5"])
|
47
|
-
end
|
48
|
-
else
|
49
|
-
s.add_dependency(%q<activesupport>, ["= 2.3.5"])
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|