unicode-display_width 1.7.0 → 2.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -2
- data/README.md +48 -13
- data/data/display_width.marshal.gz +0 -0
- data/lib/unicode/display_width.rb +23 -9
- data/lib/unicode/display_width/constants.rb +7 -5
- data/lib/unicode/display_width/index.rb +5 -3
- data/lib/unicode/display_width/no_string_ext.rb +7 -6
- data/lib/unicode/display_width/string_ext.rb +3 -11
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65e2ca3e7559abe233575caa4b9b94c09c3a9d011ece712c5a754b2b253871cb
|
4
|
+
data.tar.gz: 266717cf34ee4cd44ee69530dbd1a855d2243a642396d5ba588f4c5901adc337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d21dc665f1d47d634c82916ef1f507fd99813b51e1351927b303e4bc8e3d016da2a65cfd5d282ec281061f0b1e99899d12ff9a7b88105f44a6312497eb8c588
|
7
|
+
data.tar.gz: f67a9ea1e6fbd4383bf432d1563aafc078e15897d7b2e4136e8fcefe88ad40e512f0ebedfd75a3f41f255e15cfc9a3343c5707133a1fba75fe4cec746395c8f7
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2.0.0.pre.1 (unreleased)
|
4
4
|
|
5
|
-
-
|
5
|
+
Will be published as non-pre version on rubygems.org when Ruby 3.0 is released (December 2020)
|
6
|
+
|
7
|
+
- Introduce new class-based API, which remembers your string-width configuration. See README for details.
|
8
|
+
- Remove auto-loading of string extension
|
9
|
+
- You can: `require "unicode/display_width/string_ext"` to continue to use the string extension
|
10
|
+
- The manual opt-out `require "unicode/display_width/no_string_ext"` is not needed anymore and will
|
11
|
+
issue a warning in the future
|
12
|
+
- Remove (already deprecated) String#display_size and String#display_width aliases
|
13
|
+
|
14
|
+
Refactorings / Internal Changes:
|
15
|
+
|
16
|
+
- Freeze string literals
|
17
|
+
- The Unicode::DisplayWidth now is class, instead of a module, this enables the new config-object API
|
6
18
|
|
7
19
|
## 1.6.1
|
8
20
|
|
data/README.md
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
## Unicode::DisplayWidth [![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](https://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
2
|
|
3
|
-
Determines the monospace display width of a string in Ruby. Implementation based on [EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby.
|
3
|
+
Determines the monospace display width of a string in Ruby. Implementation based on [EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) and other data, 100% in Ruby. It does not rely on the OS vendor (like [wcwidth()](https://github.com/janlelis/wcswidth-ruby)) to provide an up-to-date method for measuring string width.
|
4
4
|
|
5
|
-
Unicode version: **
|
5
|
+
Unicode version: **12.1.0** (May 2019)
|
6
6
|
|
7
7
|
Supported Rubies: **2.7**, **2.6**, **2.5**, **2.4**
|
8
8
|
|
9
|
-
Old Rubies
|
9
|
+
Old Rubies which might still work: **2.3**, **2.2**, **2.1**, **2.0**, **1.9**
|
10
|
+
|
11
|
+
## Version 2.0.pre1 — Breaking Changes
|
12
|
+
|
13
|
+
Some features of this library have been marked deprecated for a long time and will be removed with Version 2.0, which will be released December 2020:
|
14
|
+
|
15
|
+
- Aliases of display_width (…\_size, …\_length) have been removed
|
16
|
+
- Auto-loading of string core extension has been removed:
|
17
|
+
|
18
|
+
If you are relying on the `String#display_width` string extension to be automatically loaded (old behavior), please load it explicitly now:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require "unicode-display_width/string_ext"
|
22
|
+
```
|
23
|
+
|
24
|
+
You could also change your `Gemfile` line to achieve this:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem "unicode-display_width", require: "unicode/display_width/string_ext"
|
28
|
+
```
|
10
29
|
|
11
30
|
## Introduction to Character Widths
|
12
31
|
|
@@ -44,6 +63,8 @@ Or add to your Gemfile:
|
|
44
63
|
|
45
64
|
## Usage
|
46
65
|
|
66
|
+
### Classic API
|
67
|
+
|
47
68
|
```ruby
|
48
69
|
require 'unicode/display_width'
|
49
70
|
|
@@ -51,7 +72,7 @@ Unicode::DisplayWidth.of("⚀") # => 1
|
|
51
72
|
Unicode::DisplayWidth.of("一") # => 2
|
52
73
|
```
|
53
74
|
|
54
|
-
|
75
|
+
#### Ambiguous Characters
|
55
76
|
|
56
77
|
The second parameter defines the value returned by characters defined as ambiguous:
|
57
78
|
|
@@ -60,15 +81,15 @@ Unicode::DisplayWidth.of("·", 1) # => 1
|
|
60
81
|
Unicode::DisplayWidth.of("·", 2) # => 2
|
61
82
|
```
|
62
83
|
|
63
|
-
|
84
|
+
#### Custom Overwrites
|
64
85
|
|
65
86
|
You can overwrite how to handle specific code points by passing a hash (or even a proc) as third parameter:
|
66
87
|
|
67
88
|
```ruby
|
68
|
-
Unicode::DisplayWidth.of("a\tb", 1,
|
89
|
+
Unicode::DisplayWidth.of("a\tb", 1, "\t".ord => 10)) # => tab counted as 10, so result is 12
|
69
90
|
```
|
70
91
|
|
71
|
-
|
92
|
+
#### Emoji Support
|
72
93
|
|
73
94
|
Experimental emoji support is included. It will adjust the string's size for modifier and zero-width joiner sequences. You will need to add the [unicode-emoji](https://github.com/janlelis/unicode-emoji) gem to your Gemfile:
|
74
95
|
|
@@ -84,18 +105,32 @@ Unicode::DisplayWidth.of "🤾🏽♀️" # => 5
|
|
84
105
|
Unicode::DisplayWidth.of "🤾🏽♀️", 1, {}, emoji: true # => 2
|
85
106
|
```
|
86
107
|
|
87
|
-
|
88
|
-
|
89
|
-
Activated by default. Will be deactivated in version 2.0:
|
108
|
+
#### Usage with String Extension
|
90
109
|
|
91
110
|
```ruby
|
92
111
|
require 'unicode/display_width/string_ext'
|
93
112
|
|
94
|
-
"⚀".display_width
|
95
|
-
'一'.display_width
|
113
|
+
"⚀".display_width # => 1
|
114
|
+
'一'.display_width # => 2
|
96
115
|
```
|
97
116
|
|
98
|
-
|
117
|
+
### Modern API: Keyword-arguments Based Config Object
|
118
|
+
|
119
|
+
Version 2.0 introduces a keyword-argument based API, which allows you to save your configuration for later-reuse. This requires an extra line of code, but has the advantage that you'll need to define your string-width options only once:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
require 'unicode/display_width'
|
123
|
+
|
124
|
+
display_width = Unicode::DisplayWidth.new(
|
125
|
+
# ambiguous: 1,
|
126
|
+
overwrite: { "A".ord => 100 },
|
127
|
+
emoji: true
|
128
|
+
)
|
129
|
+
|
130
|
+
display_width.of "⚀" # => 1
|
131
|
+
display_width.of "🤾🏽♀️" # => 2
|
132
|
+
display_width.of "A" # => 100
|
133
|
+
```
|
99
134
|
|
100
135
|
### Usage From the CLI
|
101
136
|
|
Binary file
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "display_width/constants"
|
4
|
+
require_relative "display_width/index"
|
3
5
|
|
4
6
|
module Unicode
|
5
|
-
|
7
|
+
class DisplayWidth
|
6
8
|
DEPTHS = [0x10000, 0x1000, 0x100, 0x10].freeze
|
7
9
|
|
8
10
|
def self.of(string, ambiguous = 1, overwrite = {}, options = {})
|
@@ -40,12 +42,24 @@ module Unicode
|
|
40
42
|
|
41
43
|
extra_width
|
42
44
|
end
|
43
|
-
end
|
44
|
-
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def initialize(ambiguous: 1, overwrite: {}, emoji: false)
|
47
|
+
@ambiguous = ambiguous
|
48
|
+
@overwrite = overwrite
|
49
|
+
@emoji = emoji
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_config(**kwargs)
|
53
|
+
[
|
54
|
+
kwargs[:ambiguous] || @ambiguous,
|
55
|
+
kwargs[:overwrite] || @overwrite,
|
56
|
+
{ emoji: kwargs[:emoji] || @emoji },
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
def of(string, **kwargs)
|
61
|
+
self.class.of(string, *get_config(**kwargs))
|
62
|
+
end
|
63
|
+
end
|
50
64
|
end
|
51
65
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Unicode
|
2
|
-
|
3
|
-
VERSION =
|
4
|
-
UNICODE_VERSION = "
|
5
|
-
DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) +
|
6
|
-
INDEX_FILENAME =
|
4
|
+
class DisplayWidth
|
5
|
+
VERSION = "2.0.0.pre1"
|
6
|
+
UNICODE_VERSION = "12.1.0"
|
7
|
+
DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../../../data/")
|
8
|
+
INDEX_FILENAME = DATA_DIRECTORY + "/display_width.marshal.gz"
|
7
9
|
end
|
8
10
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "zlib"
|
4
|
+
require_relative "constants"
|
3
5
|
|
4
6
|
module Unicode
|
5
|
-
|
7
|
+
class DisplayWidth
|
6
8
|
File.open(INDEX_FILENAME, "rb") do |file|
|
7
9
|
serialized_data = Zlib::GzipReader.new(file).read
|
8
10
|
serialized_data.force_encoding Encoding::BINARY
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
module DisplayWidth
|
3
|
-
NO_STRING_EXT = true
|
4
|
-
end
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
3
|
+
warn "You are loading 'unicode-display_width/no_string_ext'\n" \
|
4
|
+
"Beginning with version 2.0, this is not necessary anymore\n"\
|
5
|
+
"You can just require 'unicode-display_width' now and no\n"\
|
6
|
+
"string extension will be loaded"
|
7
|
+
|
8
|
+
require_relative "../display_width"
|
@@ -1,17 +1,9 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../display_width" unless defined? Unicode::DisplayWidth
|
2
4
|
|
3
5
|
class String
|
4
6
|
def display_width(ambiguous = 1, overwrite = {}, options = {})
|
5
7
|
Unicode::DisplayWidth.of(self, ambiguous, overwrite, options)
|
6
8
|
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
9
|
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:
|
4
|
+
version: 2.0.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.4'
|
41
|
-
description: "[Unicode
|
41
|
+
description: "[Unicode 12.1.0] Determines the monospace display width of a string
|
42
42
|
using EastAsianWidth.txt, Unicode general category, and other data."
|
43
43
|
email:
|
44
44
|
- hi@ruby.consulting
|
@@ -76,11 +76,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
version: 1.9.3
|
77
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
81
|
+
version: 1.3.1
|
82
82
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
83
|
+
rubygems_version: 3.0.6
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: Determines the monospace display width of a string in Ruby.
|