ansel 2.0.1 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.md +17 -25
- data/ansel.gemspec +4 -5
- data/lib/ansel/character_map.rb +564 -562
- data/lib/ansel/converter.rb +11 -13
- data/lib/ansel/version.rb +1 -1
- metadata +8 -13
- data/Gemfile +0 -7
- data/Gemfile.lock +0 -33
- data/Gemfile.travis +0 -11
- data/Rakefile +0 -17
data/lib/ansel/converter.rb
CHANGED
@@ -6,8 +6,7 @@ module ANSEL
|
|
6
6
|
|
7
7
|
def initialize(to_charset = 'UTF-8')
|
8
8
|
@to_charset = to_charset
|
9
|
-
@encoding_converter = Encoding::Converter.new(
|
10
|
-
@ansi_to_utf16_map = @@non_combining.merge(@@combining)
|
9
|
+
@encoding_converter = Encoding::Converter.new('UTF-16BE', 'UTF-8')
|
11
10
|
end
|
12
11
|
|
13
12
|
def utf16_to_utf8(string)
|
@@ -17,7 +16,7 @@ module ANSEL
|
|
17
16
|
def convert(string)
|
18
17
|
output = ''
|
19
18
|
scanner = StringScanner.new(string)
|
20
|
-
until scanner.eos?
|
19
|
+
until scanner.eos?
|
21
20
|
byte = scanner.get_byte
|
22
21
|
char = byte.unpack('C')[0]
|
23
22
|
char_hex = char.to_s(16).upcase
|
@@ -26,27 +25,26 @@ module ANSEL
|
|
26
25
|
when 0x00..0x7F
|
27
26
|
output << byte
|
28
27
|
when 0x88..0xC8
|
29
|
-
output << utf16_to_utf8(
|
30
|
-
scanner.get_byte
|
28
|
+
output << utf16_to_utf8(ANSI_TO_UTF16_MAP[char_hex] || ANSI_TO_UTF16_MAP['ERR'])
|
29
|
+
scanner.get_byte if scanner.check(/\00/)
|
31
30
|
when 0xE0..0xFB
|
32
31
|
[2, 1, 0].each do |n| # try 3 bytes, then 2 bytes, then 1 byte
|
33
32
|
bytes = [char_hex]
|
34
|
-
scanner.peek(n).each_byte {|b| bytes << b.to_s(16).upcase}
|
33
|
+
scanner.peek(n).each_byte { |b| bytes << b.to_s(16).upcase }
|
35
34
|
hex_key = bytes.join('+')
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
next unless ANSI_TO_UTF16_MAP.key?(hex_key)
|
36
|
+
|
37
|
+
output << utf16_to_utf8(ANSI_TO_UTF16_MAP[hex_key])
|
38
|
+
n.times { scanner.get_byte }
|
39
|
+
break
|
41
40
|
end
|
42
41
|
else
|
43
|
-
output << utf16_to_utf8(
|
42
|
+
output << utf16_to_utf8(ANSI_TO_UTF16_MAP['ERR'])
|
44
43
|
scanner.get_byte if scanner.get_byte.unpack('C')[0] >= 0xE0 # ignore the next byte
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
48
47
|
output
|
49
48
|
end
|
50
|
-
|
51
49
|
end
|
52
50
|
end
|
data/lib/ansel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Convert ANSEL encoded text to UTF-8
|
14
14
|
email: keithm@infused.org
|
@@ -17,15 +17,11 @@ extensions: []
|
|
17
17
|
extra_rdoc_files:
|
18
18
|
- README.md
|
19
19
|
- CHANGELOG.md
|
20
|
-
-
|
20
|
+
- LICENSE
|
21
21
|
files:
|
22
22
|
- CHANGELOG.md
|
23
|
-
-
|
24
|
-
- Gemfile.lock
|
25
|
-
- Gemfile.travis
|
26
|
-
- MIT-LICENSE
|
23
|
+
- LICENSE
|
27
24
|
- README.md
|
28
|
-
- Rakefile
|
29
25
|
- ansel.gemspec
|
30
26
|
- lib/ansel.rb
|
31
27
|
- lib/ansel/character_map.rb
|
@@ -34,7 +30,7 @@ files:
|
|
34
30
|
homepage: http://github.com/infused/ansel
|
35
31
|
licenses: []
|
36
32
|
metadata: {}
|
37
|
-
post_install_message:
|
33
|
+
post_install_message:
|
38
34
|
rdoc_options:
|
39
35
|
- "--charset=UTF-8"
|
40
36
|
require_paths:
|
@@ -50,9 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
46
|
- !ruby/object:Gem::Version
|
51
47
|
version: 1.3.0
|
52
48
|
requirements: []
|
53
|
-
|
54
|
-
|
55
|
-
signing_key:
|
49
|
+
rubygems_version: 3.4.13
|
50
|
+
signing_key:
|
56
51
|
specification_version: 4
|
57
52
|
summary: Convert ANSEL encoded text to UTF-8
|
58
53
|
test_files: []
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
ansel (2.0.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
diff-lcs (1.2.5)
|
10
|
-
rake (11.1.0)
|
11
|
-
rspec (3.1.0)
|
12
|
-
rspec-core (~> 3.1.0)
|
13
|
-
rspec-expectations (~> 3.1.0)
|
14
|
-
rspec-mocks (~> 3.1.0)
|
15
|
-
rspec-core (3.1.7)
|
16
|
-
rspec-support (~> 3.1.0)
|
17
|
-
rspec-expectations (3.1.2)
|
18
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
-
rspec-support (~> 3.1.0)
|
20
|
-
rspec-mocks (3.1.3)
|
21
|
-
rspec-support (~> 3.1.0)
|
22
|
-
rspec-support (3.1.2)
|
23
|
-
|
24
|
-
PLATFORMS
|
25
|
-
ruby
|
26
|
-
|
27
|
-
DEPENDENCIES
|
28
|
-
ansel!
|
29
|
-
rake
|
30
|
-
rspec
|
31
|
-
|
32
|
-
BUNDLED WITH
|
33
|
-
1.11.2
|
data/Gemfile.travis
DELETED
data/Rakefile
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: ascii-8bit
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler/setup';
|
5
|
-
Bundler.setup(:default, :development)
|
6
|
-
|
7
|
-
require 'rspec/core/rake_task'
|
8
|
-
RSpec::Core::RakeTask.new :spec do |t|
|
9
|
-
t.rspec_opts = %w(--color)
|
10
|
-
end
|
11
|
-
|
12
|
-
task :default => :spec
|
13
|
-
|
14
|
-
desc "Open an irb session preloaded with this library"
|
15
|
-
task :console do
|
16
|
-
sh "irb -rubygems -I lib -r ansel.rb"
|
17
|
-
end
|