unicode-display_width 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +7 -4
- data/data/display_width.marshal.gz +0 -0
- data/lib/unicode/display_width/constants.rb +2 -2
- data/lib/unicode/display_width.rb +10 -0
- 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: e64e9230d9a0df4076a18bb935b6f1aeac16e079544aa65097b1ddb967b4960c
|
4
|
+
data.tar.gz: 17d5cf547c89859318bc578e3e15a63ce0ab94d8801f2928097bb29d27cb6da0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea3ee4075d687ac1708a095ffe82e833389db1ec613ef43c9f8aa3aeeb5983d585cf6ad22e7d00d1020378344d9e9450096d6b7a04f27358d5418466b7fdf41
|
7
|
+
data.tar.gz: 00a75b4f46daa89186bde97d5e2da86d197e5ef8704876c16085dd9a503620dc2aaf6e6e9030b9a438417f54d48070d0df06ca2b3e1530bc6d2d1be761f21054
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
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://github.com/janlelis/unicode-display_width/workflows/Test/badge.svg" />](https://github.com/janlelis/unicode-display_width/actions?query=workflow%3ATest)
|
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. 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.
|
3
|
+
Determines the monospace display width of a string in Ruby. Useful for all kinds of terminal-based applications. 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: **15.0.0** (September 2022)
|
6
6
|
|
7
7
|
Supported Rubies: **3.1**, **3.0**, **2.7**
|
8
8
|
|
9
|
-
Old Rubies which might still work: **2.6**, **2.5**, **2.4
|
9
|
+
Old Rubies which might still work: **2.6**, **2.5**, **2.4**
|
10
|
+
|
11
|
+
For even older Rubies, use version 2.3.0 of this gem: **2.3**, **2.2**, **2.1**, **2.0**, **1.9**
|
10
12
|
|
11
13
|
## Version 2.0 — Breaking Changes
|
12
14
|
|
@@ -39,7 +41,7 @@ Width | Characters | Comment
|
|
39
41
|
-------|------------------------------|--------------------------------------------------
|
40
42
|
X | (user defined) | Overwrites any other values
|
41
43
|
-1 | `"\b"` | Backspace (total width never below 0)
|
42
|
-
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)
|
44
|
+
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) which do not change horizontal width
|
43
45
|
1 | `"\u{00AD}"` | SOFT HYPHEN
|
44
46
|
2 | `"\u{2E3A}"` | TWO-EM DASH
|
45
47
|
3 | `"\u{2E3B}"` | THREE-EM DASH
|
@@ -148,6 +150,7 @@ Replace "一" with the actual string to measure
|
|
148
150
|
- JavaScript: https://github.com/mycoboco/wcwidth.js
|
149
151
|
- C: https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
|
150
152
|
- C for Julia: https://github.com/JuliaLang/utf8proc/issues/2
|
153
|
+
- Golang: https://github.com/rivo/uniseg
|
151
154
|
|
152
155
|
See [unicode-x](https://github.com/janlelis/unicode-x) for more Unicode related micro libraries.
|
153
156
|
|
Binary file
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Unicode
|
4
4
|
class DisplayWidth
|
5
|
-
VERSION = "2.
|
6
|
-
UNICODE_VERSION = "
|
5
|
+
VERSION = "2.4.0"
|
6
|
+
UNICODE_VERSION = "15.0.0"
|
7
7
|
DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../../../data/")
|
8
8
|
INDEX_FILENAME = DATA_DIRECTORY + "/display_width.marshal.gz"
|
9
9
|
end
|
@@ -6,8 +6,15 @@ require_relative "display_width/index"
|
|
6
6
|
module Unicode
|
7
7
|
class DisplayWidth
|
8
8
|
DEPTHS = [0x10000, 0x1000, 0x100, 0x10].freeze
|
9
|
+
ASCII_NON_ZERO_REGEX = /[\0\x05\a\b\n\v\f\r\x0E\x0F]/
|
9
10
|
|
10
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? && !string.match?(ASCII_NON_ZERO_REGEX)
|
14
|
+
return string.size
|
15
|
+
end
|
16
|
+
|
17
|
+
# Add width of each char
|
11
18
|
res = string.codepoints.inject(0){ |total_width, codepoint|
|
12
19
|
index_or_value = INDEX
|
13
20
|
codepoint_depth_offset = codepoint
|
@@ -21,7 +28,10 @@ module Unicode
|
|
21
28
|
total_width + (overwrite[codepoint] || width || 1)
|
22
29
|
}
|
23
30
|
|
31
|
+
# Substract emoji error
|
24
32
|
res -= emoji_extra_width_of(string, ambiguous, overwrite) if options[:emoji]
|
33
|
+
|
34
|
+
# Return result + prevent negative lengths
|
25
35
|
res < 0 ? 0 : res
|
26
36
|
end
|
27
37
|
|
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: 2.
|
4
|
+
version: 2.4.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:
|
11
|
+
date: 2023-01-03 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: '13.0'
|
41
|
-
description: "[Unicode
|
41
|
+
description: "[Unicode 15.0.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
|
@@ -62,7 +62,7 @@ homepage: https://github.com/janlelis/unicode-display_width
|
|
62
62
|
licenses:
|
63
63
|
- MIT
|
64
64
|
metadata:
|
65
|
-
changelog_uri: https://github.com/janlelis/unicode-display_width/blob/
|
65
|
+
changelog_uri: https://github.com/janlelis/unicode-display_width/blob/main/CHANGELOG.md
|
66
66
|
source_code_uri: https://github.com/janlelis/unicode-display_width
|
67
67
|
bug_tracker_uri: https://github.com/janlelis/unicode-display_width/issues
|
68
68
|
rubygems_mfa_required: 'true'
|
@@ -74,14 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
74
|
requirements:
|
75
75
|
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 2.4.0
|
78
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
|
-
rubygems_version: 3.3.
|
84
|
+
rubygems_version: 3.3.7
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Determines the monospace display width of a string in Ruby.
|