unicode-display_width 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +13 -1
- data/MIT-LICENSE.txt +1 -1
- data/README.md +98 -0
- data/Rakefile +4 -25
- data/data/unicode-width.index +0 -0
- data/lib/unicode/display_width.rb +22 -45
- data/lib/unicode/display_width/constants.rb +7 -0
- data/lib/unicode/display_width/index.rb +7 -0
- data/lib/unicode/display_width/index_builder.rb +68 -0
- data/lib/unicode/display_width/no_string_ext.rb +7 -0
- data/lib/unicode/display_width/string_ext.rb +17 -0
- data/spec/display_width_spec.rb +126 -0
- data/unicode-display_width.gemspec +4 -5
- metadata +16 -11
- data/README.rdoc +0 -38
- data/data/EastAsianWidth.index +0 -0
- data/lib/unicode/display_size.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e33d3077d16ee2ad442841b2e30f4e6166597a1c
|
4
|
+
data.tar.gz: 23bd47c3b47e3ffe0795a94315f2629d669e58e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a0db88800f45f0e7cd53247b338bad6ae9c3c7682223f50e9c8fdeb0a5e6873a6e6449581283e1836d26ae90c6914a8889c9560f419f7fc6b28ab1201eda73
|
7
|
+
data.tar.gz: d4d6e252efe9b804c519e5a9e456a64ca99fedbd6fd67280878c22cec81813e9f147f7818a28f274491ff1adfd8fd283079cce522ffc8e9160f3431fd41c8705
|
data/CHANGELOG.txt
CHANGED
@@ -1,7 +1,19 @@
|
|
1
|
+
## 1.0.0
|
2
|
+
|
3
|
+
* Faster than 0.3.1
|
4
|
+
* Advanced determination of character width
|
5
|
+
* This includes: Treat width of most chars of general categories (Mn, Me, Cf) as 0
|
6
|
+
* This includes: Introduce list of characters with special widths
|
7
|
+
* Allow custom overrides for specific codepoints
|
8
|
+
* Set required Ruby version to 2.0
|
9
|
+
* Add NO_STRING_EXT mode to disable monkey patching
|
10
|
+
* Internal API & index format changed drastically
|
11
|
+
* Remove require 'unicode/display_size' (use 'unicode/display_width' instead)
|
12
|
+
|
1
13
|
## 0.3.1
|
2
14
|
|
3
15
|
* Faster than 0.3.0
|
4
|
-
* Deprecate usage of aliases: String#display_size and String#
|
16
|
+
* Deprecate usage of aliases: String#display_size and String#display_length
|
5
17
|
* Eliminate Ruby warnings (@amatsuda)
|
6
18
|
|
7
19
|
## 0.3.0
|
data/MIT-LICENSE.txt
CHANGED
data/README.md
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
## Unicode::DisplayWidth [![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](http://badge.fury.io/rb/unicode-display_width) [<img src="https://travis-ci.org/janlelis/unicode-display_width.png" />](https://travis-ci.org/janlelis/unicode-display_width)
|
2
|
+
|
3
|
+
Determines the monospace display width of a string in Ruby. Implementation based on [EastAsianWidth.txt](http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby. You can also use [wcswidth-ruby](https://github.com/janlelis/wcswidth-ruby) for the same purpose, but it is less often updated by OS vendors, so results may differ.
|
4
|
+
|
5
|
+
## Introduction to Character Widths
|
6
|
+
|
7
|
+
Guesing the correct space a character will consume on terminals is not easy. There is no single standard. Most implementations combine data from [East Asian Width](http://www.unicode.org/reports/tr11/), some [General Categories](https://en.wikipedia.org/wiki/Unicode_character_property#General_Category), and hand-picked adjustments.
|
8
|
+
|
9
|
+
### How this Library Handles Widths
|
10
|
+
|
11
|
+
As of version 1.0.0. Further at the top means higher precedence. Please expect changes to this algorithm with every MINOR version update (the X in 1.X.0)!
|
12
|
+
|
13
|
+
Width | Characters | Comment
|
14
|
+
-------|------------------------------|--------------------------------------------------
|
15
|
+
X | (user defined) | Overwrites any other values
|
16
|
+
-1 | `"\b"` | Backspace (total width never below 0)
|
17
|
+
0 | `"\0"`, `"\x05"`, `"\a"`, `"\n"`, `"\v"`, `"\f"`, `"\r"`, `"\x0E"`, `"\x0F"` | [C0 control codes](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_.28ASCII_and_derivatives.29) that do not change horizontal width
|
18
|
+
1 | `"\u{00AD}"` | SOFT HYPHEN
|
19
|
+
2 | `"\u{2E3A}"` | TWO-EM DASH
|
20
|
+
3 | `"\u{2E3B}"` | THREE-EM DASH
|
21
|
+
0 | General Categories: Mn, Me, Cf (non-arabic) | Excludes ARABIC format characters
|
22
|
+
0 | `"\u{1160}".."\u{11FF}"` | HANGUL JUNGSEONG
|
23
|
+
2 | East Asian Width: F, W | Full-width characters
|
24
|
+
1 or 2 | East Asian Width: A | Ambiguous characters, user defined, default: 1
|
25
|
+
1 | All other codepoints | -
|
26
|
+
|
27
|
+
## Install
|
28
|
+
|
29
|
+
Install the gem with:
|
30
|
+
|
31
|
+
gem install unicode-display_width
|
32
|
+
|
33
|
+
Or add to your Gemfile:
|
34
|
+
|
35
|
+
gem 'unicode-display_width'
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
require 'unicode/display_width'
|
41
|
+
|
42
|
+
Unicode::DisplayWidth.of("⚀") # => 1
|
43
|
+
Unicode::DisplayWidth.of("一") # => 2
|
44
|
+
```
|
45
|
+
|
46
|
+
### Ambiguous Characters
|
47
|
+
|
48
|
+
The second parameter defines the value returned by characterrs defined as ambiguous:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Unicode::DisplayWidth.of("·", 1) # => 1
|
52
|
+
Unicode::DisplayWidth.of("·", 2) # => 2
|
53
|
+
```
|
54
|
+
|
55
|
+
### Custom Overwrites
|
56
|
+
|
57
|
+
You can overwrite how to handle specific code points by passing a hash (or even a proc) as third parameter:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
Unicode::DisplayWidth.of("a\tb", 1, 0x09 => 10)) # => 12
|
61
|
+
```
|
62
|
+
|
63
|
+
### Usage with String Extension
|
64
|
+
|
65
|
+
Activated by default. Will be deactivated in version 2.0:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'unicode/display_width/string_ext'
|
69
|
+
|
70
|
+
"⚀".display_width #=> 1
|
71
|
+
'一'.display_width #=> 2
|
72
|
+
```
|
73
|
+
|
74
|
+
You can actively opt-out from the string extension with: `require 'unicode/display_width/no_string_ext'`
|
75
|
+
|
76
|
+
### Usage From the CLI
|
77
|
+
|
78
|
+
If you are not a Ruby developer, but you still want to use this software to print out display widths for strings:
|
79
|
+
|
80
|
+
```
|
81
|
+
$ gem install unicode-display_width
|
82
|
+
$ ruby -r unicode/display_width -e 'puts Unicode::DisplayWidth.of $*[0]' -- "一"
|
83
|
+
```
|
84
|
+
Replace "一" with the actual string to measure
|
85
|
+
|
86
|
+
## Other Implementations & Discussion
|
87
|
+
|
88
|
+
- Python: https://github.com/jquast/wcwidth
|
89
|
+
- JavaScript: https://github.com/mycoboco/wcwidth.js
|
90
|
+
- C: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
|
91
|
+
- C for Julia: https://github.com/JuliaLang/utf8proc/issues/2
|
92
|
+
|
93
|
+
## Copyright & Info
|
94
|
+
|
95
|
+
- Copyright (c) 2011, 2015-2016 Jan Lelis, http://janlelis.com, released under the MIT
|
96
|
+
license
|
97
|
+
- Early versions based on runpaint's unicode-data interface: Copyright (c) 2009 Run Paint Run Run
|
98
|
+
- Unicode data: http://www.unicode.org/copyright.html#Exhibit1
|
data/Rakefile
CHANGED
@@ -45,26 +45,8 @@ task :default => :test
|
|
45
45
|
namespace :update do
|
46
46
|
desc "#{gemspec.name} | Update index"
|
47
47
|
task :index do
|
48
|
-
require File.dirname(__FILE__) + '/lib/unicode/display_width'
|
49
|
-
|
50
|
-
data.rewind
|
51
|
-
table = {}
|
52
|
-
dir = File.dirname Unicode::DisplayWidth::TABLE_FILE
|
53
|
-
Dir.mkdir(dir) unless Dir.exists?(dir)
|
54
|
-
data.each_line{ |line|
|
55
|
-
line =~ /^(\S+?);(\S+)\s+#.*$/
|
56
|
-
if $1 && $2
|
57
|
-
cps, width = $1, $2
|
58
|
-
if cps['..']
|
59
|
-
range = Range.new(*cps.split('..').map{ |cp| cp.to_i(16) })
|
60
|
-
range.each{ |cp| table[ cp ] = width.to_sym }
|
61
|
-
else
|
62
|
-
table[ cps.to_i(16) ] = width.to_sym
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
}
|
67
|
-
File.open(Unicode::DisplayWidth::TABLE_FILE, 'wb') { |f| Marshal.dump(table, f) }
|
48
|
+
require File.dirname(__FILE__) + '/lib/unicode/display_width/index_builder'
|
49
|
+
Unicode::DisplayWidth::IndexBuilder.build!
|
68
50
|
end
|
69
51
|
end
|
70
52
|
|
@@ -74,11 +56,8 @@ end
|
|
74
56
|
namespace :update do
|
75
57
|
desc "#{gemspec.name} | Update unicode data"
|
76
58
|
task :data do
|
77
|
-
require File.dirname(__FILE__) + '/lib/unicode/display_width'
|
78
|
-
|
79
|
-
open("http://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt") { |f|
|
80
|
-
File.write(Unicode::DisplayWidth::DATA_FILE, f.read)
|
81
|
-
}
|
59
|
+
require File.dirname(__FILE__) + '/lib/unicode/display_width/index_builder'
|
60
|
+
Unicode::DisplayWidth::IndexBuilder.fetch!
|
82
61
|
end
|
83
62
|
end
|
84
63
|
|
Binary file
|
@@ -1,56 +1,33 @@
|
|
1
|
-
|
1
|
+
require_relative 'display_width/constants'
|
2
2
|
|
3
3
|
module Unicode
|
4
4
|
module DisplayWidth
|
5
|
-
|
6
|
-
|
7
|
-
TABLE_FILE = (DATA_DIR + 'EastAsianWidth.index').freeze
|
8
|
-
DATA_FILE = (DATA_DIR + 'EastAsianWidth.txt').freeze
|
5
|
+
def self.of(string, ambiguous = 1, overwrite = {})
|
6
|
+
require_relative 'display_width/index' unless defined? ::Unicode::DisplayWidth::INDEX
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
res = string.unpack('U*').inject(0){ |total_width, codepoint|
|
9
|
+
total_width + (
|
10
|
+
overwrite[codepoint] || case width = INDEX[codepoint]
|
11
|
+
when Integer
|
12
|
+
width
|
13
|
+
when :F, :W
|
14
|
+
2
|
15
|
+
when :A
|
16
|
+
ambiguous
|
17
|
+
else # including :N, :Na, :H
|
18
|
+
1
|
19
|
+
end
|
20
|
+
)
|
21
|
+
}
|
18
22
|
|
19
|
-
|
20
|
-
n = n.to_s.unpack('U')[0] unless n.is_a? Integer
|
21
|
-
table[n] or raise ArgumentError, 'codepoint not found'
|
22
|
-
end
|
23
|
-
alias width codepoint
|
24
|
-
alias of codepoint
|
23
|
+
res < 0 ? 0 : res
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
when 'F', 'W'
|
34
|
-
2
|
35
|
-
when 'N', 'Na', 'H'
|
36
|
-
1
|
37
|
-
when 'A'
|
38
|
-
ambiguous
|
39
|
-
else
|
40
|
-
1
|
41
|
-
end
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
def display_size(*args)
|
46
|
-
warn "Deprecation warning: Please use `String#display_width` instead of `String#display_size`"
|
47
|
-
display_width(*args)
|
48
|
-
end
|
49
|
-
|
50
|
-
def display_length(*args)
|
51
|
-
warn "Deprecation warning: Please use `String#display_width` instead of `String#display_length`"
|
52
|
-
display_width(*args)
|
53
|
-
end
|
28
|
+
# Allows you to opt-out of the default string extension. Will eventually be removed,
|
29
|
+
# so you must opt-in for the core extension by requiring 'display_width/string_ext'
|
30
|
+
unless defined?(Unicode::DisplayWidth::NO_STRING_EXT) && Unicode::DisplayWidth::NO_STRING_EXT
|
31
|
+
require_relative 'display_width/string_ext'
|
54
32
|
end
|
55
33
|
|
56
|
-
# J-_-L
|
@@ -0,0 +1,68 @@
|
|
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
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../display_width'
|
2
|
+
|
3
|
+
class String
|
4
|
+
def display_width(ambiguous = 1, overwrite = {})
|
5
|
+
Unicode::DisplayWidth.of(self, ambiguous, overwrite)
|
6
|
+
end
|
7
|
+
|
8
|
+
def display_size(*args)
|
9
|
+
warn "Deprecation warning: Please use `String#display_width` instead of `String#display_size`"
|
10
|
+
display_width(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def display_length(*args)
|
14
|
+
warn "Deprecation warning: Please use `String#display_width` instead of `String#display_length`"
|
15
|
+
display_width(*args)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'unicode/display_width'
|
4
|
+
|
5
|
+
describe 'Unicode::DisplayWidth.of' do
|
6
|
+
describe '[east asian width]' do
|
7
|
+
it 'returns 2 for F' do
|
8
|
+
expect( '!'.display_width ).to eq 2
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns 2 for W' do
|
12
|
+
expect( '一'.display_width ).to eq 2
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns 1 for N' do
|
16
|
+
expect( 'À'.display_width ).to eq 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns 1 for Na' do
|
20
|
+
expect( 'A'.display_width ).to eq 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns 1 for H' do
|
24
|
+
expect( '。'.display_width ).to eq 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns first argument of display_width for A' do
|
28
|
+
expect( '·'.display_width(1) ).to eq 1
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns first argument of display_width for A' do
|
32
|
+
expect( '·'.display_width(2) ).to eq 2
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns 1 for A if no argument given' do
|
36
|
+
expect( '·'.display_width ).to eq 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '[zero width]' do
|
41
|
+
it 'returns 0 for Mn chars' do
|
42
|
+
expect( 'ֿ'.display_width ).to eq 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns 0 for Me chars' do
|
46
|
+
expect( '҈'.display_width ).to eq 0
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns 0 for Cf chars' do
|
50
|
+
expect( ''.display_width ).to eq 0
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns 0 for HANGUL JUNGSEONG chars' do
|
54
|
+
expect( 'ᅠ'.display_width ).to eq 0
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '[special characters]' do
|
59
|
+
it 'returns 0 for ␀' do
|
60
|
+
expect( "\0".display_width ).to eq 0
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns 0 for ␅' do
|
64
|
+
expect( "\x05".display_width ).to eq 0
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns 0 for ␇' do
|
68
|
+
expect( "\a".display_width ).to eq 0
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns -1 for ␈' do
|
72
|
+
expect( "aaaa\b".display_width ).to eq 3
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns -1 for ␈, but at least 0' do
|
76
|
+
expect( "\b".display_width ).to eq 0
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns 0 for ␊' do
|
80
|
+
expect( "\n".display_width ).to eq 0
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'returns 0 for ␋' do
|
84
|
+
expect( "\v".display_width ).to eq 0
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns 0 for ␌' do
|
88
|
+
expect( "\f".display_width ).to eq 0
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'returns 0 for ␍' do
|
92
|
+
expect( "\r".display_width ).to eq 0
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'returns 0 for ␎' do
|
96
|
+
expect( "\x0E".display_width ).to eq 0
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns 0 for ␏' do
|
100
|
+
expect( "\x0F".display_width ).to eq 0
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns 1 for other C0 characters' do
|
104
|
+
expect( "\x10".display_width ).to eq 1
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'returns 1 for SOFT HYPHEN' do
|
108
|
+
expect( "".display_width ).to eq 1
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns 2 for THREE-EM DASH' do
|
112
|
+
expect( "⸺".display_width ).to eq 2
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'returns 3 for THREE-EM DASH' do
|
116
|
+
expect( "⸻".display_width ).to eq 3
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
describe '[overwrite]' do
|
122
|
+
it 'can be passed a 3rd parameter with overwrites' do
|
123
|
+
expect( "\t".display_width(1, 0x09 => 12) ).to eq 12
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require 'rubygems' unless defined? Gem
|
3
2
|
require File.dirname(__FILE__) + "/lib/unicode/display_width"
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
@@ -10,10 +9,10 @@ Gem::Specification.new do |s|
|
|
10
9
|
s.homepage = "http://github.com/janlelis/unicode-display_width"
|
11
10
|
s.summary = "Support for east_asian_width string widths."
|
12
11
|
s.description = "This gem adds String#display_width to get the display size of a string using EastAsianWidth.txt."
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt", "CHANGELOG.txt"]
|
12
|
+
s.files = Dir.glob(%w[{lib,spec}/**/*.rb [A-Z]*.{txt,rdoc} data/unicode-width.index]) + %w{Rakefile unicode-display_width.gemspec}
|
13
|
+
s.extra_rdoc_files = ["README.md", "MIT-LICENSE.txt", "CHANGELOG.txt"]
|
16
14
|
s.license = 'MIT'
|
17
|
-
s.
|
15
|
+
s.required_ruby_version = '~> 2.0'
|
16
|
+
s.add_development_dependency 'rspec', '~> 3.4'
|
18
17
|
s.add_development_dependency 'rake', '~> 10.4'
|
19
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: 0.
|
4
|
+
version: 1.0.0
|
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-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.4'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,17 +44,22 @@ email: mail@janlelis.de
|
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files:
|
47
|
-
- README.
|
47
|
+
- README.md
|
48
48
|
- MIT-LICENSE.txt
|
49
49
|
- CHANGELOG.txt
|
50
50
|
files:
|
51
51
|
- CHANGELOG.txt
|
52
52
|
- MIT-LICENSE.txt
|
53
|
-
- README.
|
53
|
+
- README.md
|
54
54
|
- Rakefile
|
55
|
-
- data/
|
56
|
-
- lib/unicode/display_size.rb
|
55
|
+
- data/unicode-width.index
|
57
56
|
- lib/unicode/display_width.rb
|
57
|
+
- lib/unicode/display_width/constants.rb
|
58
|
+
- lib/unicode/display_width/index.rb
|
59
|
+
- lib/unicode/display_width/index_builder.rb
|
60
|
+
- lib/unicode/display_width/no_string_ext.rb
|
61
|
+
- lib/unicode/display_width/string_ext.rb
|
62
|
+
- spec/display_width_spec.rb
|
58
63
|
- unicode-display_width.gemspec
|
59
64
|
homepage: http://github.com/janlelis/unicode-display_width
|
60
65
|
licenses:
|
@@ -66,14 +71,14 @@ require_paths:
|
|
66
71
|
- lib
|
67
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
73
|
requirements:
|
69
|
-
- - "
|
74
|
+
- - "~>"
|
70
75
|
- !ruby/object:Gem::Version
|
71
|
-
version: '0'
|
76
|
+
version: '2.0'
|
72
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
78
|
requirements:
|
74
79
|
- - ">="
|
75
80
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
81
|
+
version: '0'
|
77
82
|
requirements: []
|
78
83
|
rubyforge_project:
|
79
84
|
rubygems_version: 2.5.1
|
data/README.rdoc
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
== unicode/display_width {<img src="https://travis-ci.org/janlelis/unicode-display_width.png" />}[https://travis-ci.org/janlelis/unicode-display_width]
|
2
|
-
|
3
|
-
An early draft of a way to determine the size of the characters using <tt>EastAsianWidth.txt</tt>, based on the very early draft of a {Ruby interface to UnicodeData.txt}[https://github.com/runpaint/unicode-data] by runpaint.
|
4
|
-
|
5
|
-
== Install
|
6
|
-
|
7
|
-
Install the gem with:
|
8
|
-
|
9
|
-
gem install unicode-display_width
|
10
|
-
|
11
|
-
or add to your Gemfile:
|
12
|
-
|
13
|
-
gem 'unicode-display_width'
|
14
|
-
|
15
|
-
== Usage
|
16
|
-
|
17
|
-
require 'unicode/display_width'
|
18
|
-
|
19
|
-
The easy way is to use the <tt>String#display_width</tt> method:
|
20
|
-
"⚀".display_width #=> 1
|
21
|
-
'一'.display_width #=> 2
|
22
|
-
|
23
|
-
To obtain more detailed character data, you can use the following syntax:
|
24
|
-
Unicode::DisplayWidth.codepoint( c )
|
25
|
-
|
26
|
-
=== Ambiguous Characters
|
27
|
-
|
28
|
-
The <tt>display_width</tt> method takes an optional argument, which will be used as width for characters defined as "ambigious". The default value is 1.
|
29
|
-
|
30
|
-
== Copyright
|
31
|
-
|
32
|
-
Copyright (c) 2011, 2015 Jan Lelis, http://rbjl.net, released under the MIT license.
|
33
|
-
|
34
|
-
Contains code by runpaint: Copyright (c) 2009 Run Paint Run Run
|
35
|
-
|
36
|
-
Contains EastAsianWidth.txt: Copyright (c) 1991-2015 Unicode, Inc.
|
37
|
-
|
38
|
-
J-_-L
|
data/data/EastAsianWidth.index
DELETED
Binary file
|
data/lib/unicode/display_size.rb
DELETED