unicode-display_width 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01657362aaf60cf79bb03c63bb96e01914139c7bb965dc9bed18e7988b8c6709
4
- data.tar.gz: 297cc1ab03e72a02e9f33eb4eec2dea2006f23987818083c4bc12aa168e437c3
3
+ metadata.gz: 1886b39340f01645fd4e64d032ab1611e471e60c4dbd46e3d8867125ef45232d
4
+ data.tar.gz: dc452df48efa0f7f9cd862b0390f611df83e4dcd82c640f4faa151b05022596f
5
5
  SHA512:
6
- metadata.gz: a3878d504a273e44268762fca4857bf26a9322e0e54c0afc437d953dca675822262c9aec54cb5de3d23390b4b778403b36ce0f73ba5b0f1d2c8554a1f796d210
7
- data.tar.gz: 00de0d22f3b245f16de15b3b4864ff754da04ea94eafdeaf06c0e38fec8cfb2559fbeaafc17f165534e70a386e154f70d7b071f5a226c9f64d7088bbb408cabb
6
+ metadata.gz: 85dfef303836ba1c13271144ad24f89dbc40591d9056ee187c9ee5b7b6ff1f19d8d9ebd4e21108f78a61d2e3d3c6ce44f560005e3216cf3f8fa595466c50dfc7
7
+ data.tar.gz: eae08ff81ed83a3965820aaf09ce10fd028428adf6653807d3fb87b0c96b9ae7be757d38ffa90a8a27b39a8454e4b2694109a8aaddcc75d21d0e449ce8f7f628
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 3.1.1
4
+
5
+ - Performance improvements
6
+
3
7
  ## 3.1.0
4
8
 
5
9
  **Improve Emoji support:**
data/README.md CHANGED
@@ -114,10 +114,11 @@ The `emoji:` option can be used to configure which type of Emoji should be consi
114
114
  `:all_no_vs16` | EAW (1 or 2) | 2 for all ZWJ/modifier/keycap sequences, even if they are not well-formed Emoji sequences | WezTerm
115
115
  `:possible`| 2 | 2 for all possible/well-formed Emoji sequences | ?
116
116
  `:rgi` | 2 | 2 for all [RGI Emoji](https://www.unicode.org/reports/tr51/#def_rgi_set) sequences | ?
117
- `:rgi_at` | EAW (1 or 2) | 1 or 2: Like `:rgi`, but Emoji sequences starting with a default-text Emoji have width 1 | Apple Terminal
117
+ `:rgi_at` | EAW (1 or 2) | 1 or 2: Like `:rgi`, but Emoji sequences starting with a default-text Emoji have EAW | Apple Terminal
118
118
  `:vs16` | 2 | 2 * number of partial Emoji (sequences never considered to represent a combined Emoji) | kitty?
119
119
  `false` or `:none` | EAW (1 or 2) | No Emoji adjustments | gnome-terminal, many older terminals
120
120
 
121
+ - *EAW:* East Asian Width
121
122
  - *RGI Emoji:* Emoji Recommended for General Interchange
122
123
  - *ZWJ:* Zero-width Joiner: Codepoint `U+200D`,used in many Emoji sequences
123
124
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Unicode
4
4
  class DisplayWidth
5
- VERSION = "3.1.0"
5
+ VERSION = "3.1.1"
6
6
  UNICODE_VERSION = "16.0.0"
7
7
  DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + "/../../../data/")
8
8
  INDEX_FILENAME = DATA_DIRECTORY + "/display_width.marshal.gz"
@@ -30,9 +30,17 @@ module Unicode
30
30
  rgi_at: :REGEX_INCLUDE_MQE_UQE,
31
31
  possible: :REGEX_WELL_FORMED,
32
32
  }
33
- REGEX_EMOJI_BASIC_OR_KEYCAP = Regexp.union(Unicode::Emoji::REGEX_BASIC, Unicode::Emoji::REGEX_EMOJI_KEYCAP)
34
- REGEX_EMOJI_ALL_SEQUENCES = Regexp.union(/.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?(\u{200D}.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?)+/, Unicode::Emoji::REGEX_EMOJI_KEYCAP)
35
33
  REGEX_EMOJI_NOT_POSSIBLE = /\A[#*0-9]\z/
34
+ REGEX_EMOJI_VS16 = Regexp.union(
35
+ Regexp.compile(
36
+ Unicode::Emoji::REGEX_TEXT_PRESENTATION.source +
37
+ "(?<![#*0-9])" +
38
+ "\u{FE0F}"
39
+ ),
40
+ Unicode::Emoji::REGEX_EMOJI_KEYCAP
41
+ )
42
+ REGEX_EMOJI_ALL_SEQUENCES = Regexp.union(/.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?(\u{200D}.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?)+/, Unicode::Emoji::REGEX_EMOJI_KEYCAP)
43
+ REGEX_EMOJI_ALL_SEQUENCES_AND_VS16 = Regexp.union(REGEX_EMOJI_ALL_SEQUENCES, REGEX_EMOJI_VS16)
36
44
 
37
45
  # Returns monospace display width of string
38
46
  def self.of(string, ambiguous = nil, overwrite = nil, old_options = {}, **options)
@@ -177,45 +185,23 @@ module Unicode
177
185
  mode == :rgi_at,
178
186
  ambiguous,
179
187
  )
188
+
180
189
  elsif mode == :all_no_vs16
181
- emoji_width_all(string)
190
+ no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES){ res += 2; "" }
191
+ [res, no_emoji_string]
192
+
182
193
  elsif mode == :vs16
183
- emoji_width_basic(string)
194
+ no_emoji_string = string.gsub(REGEX_EMOJI_VS16){ res += 2; "" }
195
+ [res, no_emoji_string]
196
+
184
197
  elsif mode == :all
185
- res_all, string = emoji_width_all(string)
186
- res_basic, string = emoji_width_basic(string)
187
- [res_all + res_basic, string]
198
+ no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES_AND_VS16){ res += 2; "" }
199
+ [res, no_emoji_string]
200
+
188
201
  else
189
202
  [0, string]
190
- end
191
- end
192
-
193
- # Ensure all explicit VS16 sequences have width 2
194
- def self.emoji_width_basic(string)
195
- res = 0
196
203
 
197
- no_emoji_string = string.gsub(REGEX_EMOJI_BASIC_OR_KEYCAP){ |basic_emoji|
198
- if basic_emoji.size >= 2 # VS16 present
199
- res += 2
200
- ""
201
- else
202
- basic_emoji
203
- end
204
- }
205
-
206
- [res, no_emoji_string]
207
- end
208
-
209
- # Use simplistic ZWJ/modifier/kecap sequence matching
210
- def self.emoji_width_all(string)
211
- res = 0
212
-
213
- no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES){
214
- res += 2
215
- ""
216
- }
217
-
218
- [res, no_emoji_string]
204
+ end
219
205
  end
220
206
 
221
207
  # Match possible Emoji first, then refine
@@ -241,14 +227,7 @@ module Unicode
241
227
  else
242
228
  if !strict_eaw
243
229
  # Ensure all explicit VS16 sequences have width 2
244
- emoji_candidate.gsub!(Unicode::Emoji::REGEX_BASIC){ |basic_emoji|
245
- if basic_emoji.size == 2 # VS16 present
246
- res += 2
247
- ""
248
- else
249
- basic_emoji
250
- end
251
- }
230
+ emoji_candidate.gsub!(REGEX_EMOJI_VS16){ res += 2; "" }
252
231
  end
253
232
 
254
233
  emoji_candidate
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: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Lelis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-18 00:00:00.000000000 Z
11
+ date: 2024-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode-emoji
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.4
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.0.4
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: rspec
29
35
  requirement: !ruby/object:Gem::Requirement