unicode-display_width 2.4.0 → 2.4.1
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.md +7 -0
- data/README.md +3 -0
- data/lib/unicode/display_width/constants.rb +1 -1
- data/lib/unicode/display_width.rb +21 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26234cf1d4a965966cfab38151afe61c8f0a4c2d4f31fc006a319997af7bf076
|
4
|
+
data.tar.gz: eb5c24564cc94da5378b1d5b9065f90a70fcbcff50f914cc858634825694a544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8687c39d5c62292c8d124ca9a3889c30f5f7d8e64b7e5ff79fc3b58137708bfeb844b36d32a5f73920f5e63a3cb60fc4a3f465f8505ccb8134e30d2445fc1af3
|
7
|
+
data.tar.gz: 37b073e36650f21bca8aa40cf9809a882fcd84642824ca8380542c80f3cb7a5f78c43eabe9abd6f09a73f6ee2cb5c49f60aa8b1ec72bcc8100cd411cdda15a5a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.4.1
|
4
|
+
|
5
|
+
- Improve general performance!
|
6
|
+
- Further improve performance for ASCII strings
|
7
|
+
|
8
|
+
*You should really upgrade - it's much faster now!*
|
9
|
+
|
3
10
|
## 2.4.0
|
4
11
|
- Improve performance for ASCII-only strings, by @fatkodima
|
5
12
|
- Require Ruby 2.4
|
data/README.md
CHANGED
@@ -91,6 +91,9 @@ You can overwrite how to handle specific code points by passing a hash (or even
|
|
91
91
|
Unicode::DisplayWidth.of("a\tb", 1, "\t".ord => 10)) # => tab counted as 10, so result is 12
|
92
92
|
```
|
93
93
|
|
94
|
+
Please note that using overwrites disables some perfomance optimizations of this gem.
|
95
|
+
|
96
|
+
|
94
97
|
#### Emoji Support
|
95
98
|
|
96
99
|
Emoji width support is included, but in must be activated manually. It will adjust the string's size for modifier and zero-width joiner sequences. You also need to add the [unicode-emoji](https://github.com/janlelis/unicode-emoji) gem to your Gemfile:
|
@@ -5,27 +5,33 @@ require_relative "display_width/index"
|
|
5
5
|
|
6
6
|
module Unicode
|
7
7
|
class DisplayWidth
|
8
|
-
|
8
|
+
INITIAL_DEPTH = 0x10000
|
9
9
|
ASCII_NON_ZERO_REGEX = /[\0\x05\a\b\n\v\f\r\x0E\x0F]/
|
10
10
|
|
11
11
|
def self.of(string, ambiguous = 1, overwrite = {}, options = {})
|
12
|
-
# Optimization for ASCII-only strings without control symbols
|
13
|
-
if overwrite.empty? && string.ascii_only?
|
14
|
-
|
12
|
+
# Optimization for ASCII-only strings without certain control symbols
|
13
|
+
if overwrite.empty? && string.ascii_only?
|
14
|
+
if string.match?(ASCII_NON_ZERO_REGEX)
|
15
|
+
res = string.gsub(ASCII_NON_ZERO_REGEX, "").size - string.count("\b")
|
16
|
+
return res < 0 ? 0 : res
|
17
|
+
else
|
18
|
+
return string.size
|
19
|
+
end
|
15
20
|
end
|
16
21
|
|
17
|
-
#
|
18
|
-
res = string.codepoints.
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
# Sum of all chars widths
|
23
|
+
res = string.codepoints.sum{ |codepoint|
|
24
|
+
next overwrite[codepoint] if overwrite[codepoint]
|
25
|
+
next 1 if codepoint > 15 && codepoint < 161 # very common
|
26
|
+
|
27
|
+
width = INDEX
|
28
|
+
depth = INITIAL_DEPTH
|
29
|
+
while (width = width[codepoint / depth]).is_a? Array
|
30
|
+
codepoint %= depth
|
31
|
+
depth /= 16
|
32
|
+
end
|
27
33
|
width = ambiguous if width == :A
|
28
|
-
|
34
|
+
width || 1
|
29
35
|
}
|
30
36
|
|
31
37
|
# Substract emoji error
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicode-display_width
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
84
|
+
rubygems_version: 3.4.1
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Determines the monospace display width of a string in Ruby.
|