ansel 2.0.1 → 2.0.3

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.
@@ -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("UTF-16BE", "UTF-8")
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? do
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(@ansi_to_utf16_map[char_hex] || @ansi_to_utf16_map['ERR'])
30
- scanner.get_byte # ignore the next 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
- if @ansi_to_utf16_map.has_key?(hex_key)
37
- output << utf16_to_utf8(@ansi_to_utf16_map[hex_key])
38
- n.times {scanner.get_byte}
39
- break
40
- end
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(@ansi_to_utf16_map['ERR'])
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
@@ -1,5 +1,5 @@
1
1
  # encoding: ascii-8bit
2
2
 
3
3
  module ANSEL
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.3'
5
5
  end
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.1
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: 2016-03-13 00:00:00.000000000 Z
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
- - MIT-LICENSE
20
+ - LICENSE
21
21
  files:
22
22
  - CHANGELOG.md
23
- - Gemfile
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
- rubyforge_project:
54
- rubygems_version: 2.5.1
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
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development, :test do
6
- gem 'rspec'
7
- end
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
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development, :test do
6
- gem 'rspec'
7
- end
8
-
9
- group :test do
10
- gem 'codeclimate-test-reporter', require: false
11
- end
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