unicode-display_width 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +6 -0
- data/lib/unicode/display_width.rb +10 -12
- data/lib/unicode/display_width/constants.rb +4 -3
- data/lib/unicode/display_width/index.rb +1 -1
- data/unicode-display_width.gemspec +1 -1
- metadata +3 -8
- data/data/unicode-width.index +0 -0
- data/lib/unicode/display_width/index_builder.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af67bc03745452e81cf9a29a48ed797fd82cef01
|
4
|
+
data.tar.gz: 7f85e858df6f46406060198108be6b8b14a7b6eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3fae9148367d5b39cfb04cc52cb800c53b5ed4e8bfcb5b93a8e1831d86af6a5179a00c144b993345b84020b3e4c1c56816f8d8859d283657bfc9f1521bb748e
|
7
|
+
data.tar.gz: b228d550c5d55822a1b4bf70dc2130a09bb18482dbcb96ff30c7fb4bb694ee9a1933e6b9931e7a962028d8296676b16a343c4286e355e8029f5006175c594abf
|
data/CHANGELOG.txt
CHANGED
@@ -6,18 +6,16 @@ module Unicode
|
|
6
6
|
require_relative 'display_width/index' unless defined? ::Unicode::DisplayWidth::INDEX
|
7
7
|
|
8
8
|
res = string.unpack('U*').inject(0){ |total_width, codepoint|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
)
|
9
|
+
index_or_value = INDEX
|
10
|
+
codepoint_depth_offset = codepoint
|
11
|
+
[0x10000, 0x1000, 0x100, 0x10].each{ |depth|
|
12
|
+
index_or_value = index_or_value[codepoint_depth_offset / depth]
|
13
|
+
codepoint_depth_offset = codepoint_depth_offset % depth
|
14
|
+
break unless index_or_value.is_a? Array
|
15
|
+
}
|
16
|
+
width = index_or_value.is_a?(Array) ? index_or_value[codepoint_depth_offset] : index_or_value
|
17
|
+
width = ambiguous if width == :A
|
18
|
+
total_width + (overwrite[codepoint] || width || 1)
|
21
19
|
}
|
22
20
|
|
23
21
|
res < 0 ? 0 : res
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Unicode
|
2
2
|
module DisplayWidth
|
3
|
-
VERSION = '1.0.
|
4
|
-
|
5
|
-
|
3
|
+
VERSION = '1.0.4'
|
4
|
+
UNICODE_VERSION = "8.0.0".freeze
|
5
|
+
DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + '/../../../data/').freeze
|
6
|
+
INDEX_FILENAME = (DATA_DIRECTORY + '/display_width.marshal.gz').freeze
|
6
7
|
end
|
7
8
|
end
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.files = Dir.glob(%w[{lib,spec}/**/*.rb [A-Z]*.{txt,rdoc} data/unicode-width.index]) + %w{Rakefile unicode-display_width.gemspec}
|
13
13
|
s.extra_rdoc_files = ["README.md", "MIT-LICENSE.txt", "CHANGELOG.txt"]
|
14
14
|
s.license = 'MIT'
|
15
|
-
s.required_ruby_version =
|
15
|
+
s.required_ruby_version = '>= 1.9.3'
|
16
16
|
s.add_development_dependency 'rspec', '~> 3.4'
|
17
17
|
s.add_development_dependency 'rake', '~> 10.4'
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicode-display_width
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,11 +52,9 @@ files:
|
|
52
52
|
- MIT-LICENSE.txt
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
|
-
- data/unicode-width.index
|
56
55
|
- lib/unicode/display_width.rb
|
57
56
|
- lib/unicode/display_width/constants.rb
|
58
57
|
- lib/unicode/display_width/index.rb
|
59
|
-
- lib/unicode/display_width/index_builder.rb
|
60
58
|
- lib/unicode/display_width/no_string_ext.rb
|
61
59
|
- lib/unicode/display_width/string_ext.rb
|
62
60
|
- spec/display_width_spec.rb
|
@@ -74,9 +72,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
72
|
- - ">="
|
75
73
|
- !ruby/object:Gem::Version
|
76
74
|
version: 1.9.3
|
77
|
-
- - "<"
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: 3.0.0
|
80
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
76
|
requirements:
|
82
77
|
- - ">="
|
@@ -84,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
79
|
version: '0'
|
85
80
|
requirements: []
|
86
81
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.6.3
|
88
83
|
signing_key:
|
89
84
|
specification_version: 4
|
90
85
|
summary: Determines the monospace display width of a string in Ruby.
|
data/data/unicode-width.index
DELETED
Binary file
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require_relative 'constants'
|
2
|
-
|
3
|
-
module Unicode
|
4
|
-
module DisplayWidth
|
5
|
-
module IndexBuilder
|
6
|
-
EAST_ASIAN_WIDTH_DATA_URL = "http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt".freeze
|
7
|
-
EAST_ASIAN_WIDTH_DATA_FILENAME = (DATA_DIRECTORY + 'EastAsianWidth.txt').freeze
|
8
|
-
IGNORE_CATEGORIES = %w[Cs Co Cn].freeze
|
9
|
-
ZERO_WIDTH_CATEGORIES = %w[Mn Me Cf].freeze
|
10
|
-
ZERO_WIDTH_CODEPOINTS = [*0x1160..0x11FF].freeze
|
11
|
-
SPECIAL_WIDTHS = {
|
12
|
-
0x0 => 0, # \0 NULL
|
13
|
-
0x5 => 0, # ENQUIRY
|
14
|
-
0x7 => 0, # \a BELL
|
15
|
-
0x8 => -1, # \b BACKSPACE
|
16
|
-
0xA => 0, # \n LINE FEED
|
17
|
-
0xB => 0, # \v LINE TABULATION
|
18
|
-
0xC => 0, # \f FORM FEED
|
19
|
-
0xD => 0, # \r CARRIAGE RETURN
|
20
|
-
0xE => 0, # SHIFT OUT
|
21
|
-
0xF => 0, # SHIFT IN
|
22
|
-
0x00AD => 1, # SOFT HYPHEN
|
23
|
-
0x2E3A => 2, # TWO-EM DASH
|
24
|
-
0x2E3B => 3, # THREE-EM DASH
|
25
|
-
}.freeze
|
26
|
-
|
27
|
-
def self.fetch!
|
28
|
-
require 'open-uri'
|
29
|
-
open(EAST_ASIAN_WIDTH_DATA_URL) { |f|
|
30
|
-
File.write(EAST_ASIAN_WIDTH_DATA_FILENAME, f.read)
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.build!
|
35
|
-
data = File.open(EAST_ASIAN_WIDTH_DATA_FILENAME)
|
36
|
-
data.rewind
|
37
|
-
Dir.mkdir(DATA_DIRECTORY) unless Dir.exists?(DATA_DIRECTORY)
|
38
|
-
index = {}
|
39
|
-
|
40
|
-
data.each_line{ |line|
|
41
|
-
line =~ /^(\S+?);(\S+)\s+#\s(\S+).*$/
|
42
|
-
if $1 && $2
|
43
|
-
cps, width, category = $1, $2, $3
|
44
|
-
next if IGNORE_CATEGORIES.include?(category)
|
45
|
-
if cps['..']
|
46
|
-
codepoints = Range.new(*cps.split('..').map{ |cp| cp.to_i(16) })
|
47
|
-
else
|
48
|
-
codepoints = [cps.to_i(16)]
|
49
|
-
end
|
50
|
-
|
51
|
-
codepoints.each{ |cp|
|
52
|
-
index[cp] = is_zero_width?(category, cp) ? 0 : width.to_sym
|
53
|
-
}
|
54
|
-
end
|
55
|
-
}
|
56
|
-
|
57
|
-
index.merge! SPECIAL_WIDTHS
|
58
|
-
File.open(INDEX_FILENAME, 'wb') { |f| Marshal.dump(index, f) }
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.is_zero_width?(category, cp)
|
62
|
-
( ZERO_WIDTH_CATEGORIES.include?(category) &&
|
63
|
-
[cp].pack('U') !~ /\p{Cf}(?<=\p{Arabic})/ ) ||
|
64
|
-
ZERO_WIDTH_CODEPOINTS.include?(cp)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|