Skip to content

Commit d510942

Browse files
committed
Use :all regex for Emoji pre-selection
1 parent fc78784 commit d510942

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

lib/unicode/display_width.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ class DisplayWidth
3434
rgi_at: :REGEX_INCLUDE_MQE_UQE,
3535
possible: :REGEX_WELL_FORMED,
3636
}
37-
# REGEX_NEEDS_EMOJI_HANDLING: ZWJ, VS16, MODIFIER, KEYCAP
38-
REGEX_EMOJI_NOT_POSSIBLE = /\A[#*0-9]\z/
3937
REGEX_EMOJI_VS16 = Regexp.union(
4038
Regexp.compile(
4139
Unicode::Emoji::REGEX_TEXT_PRESENTATION.source +
@@ -68,7 +66,7 @@ def self.of(string, ambiguous = nil, overwrite = nil, old_options = {}, **option
6866
return width + string.size
6967
end
7068

71-
# Retrieve Emoji width, maybe: add quick check using REGEX_NEEDS_EMOJI_HANDLING
69+
# Retrieve Emoji width
7270
if options[:emoji] != :none
7371
e_width, string = emoji_width(
7472
string,
@@ -167,13 +165,9 @@ def self.emoji_width_via_possible(string, emoji_set_regex, strict_eaw = false, a
167165
res = 0
168166

169167
# For each string possibly an emoji
170-
no_emoji_string = string.gsub(Unicode::Emoji::REGEX_POSSIBLE){ |emoji_candidate|
171-
# Skip notorious false positives
172-
if REGEX_EMOJI_NOT_POSSIBLE.match?(emoji_candidate)
173-
emoji_candidate
174-
168+
no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES_AND_VS16){ |emoji_candidate|
175169
# Check if we have a combined Emoji with width 2 (or EAW an Apple Terminal)
176-
elsif emoji_candidate == emoji_candidate[emoji_set_regex]
170+
if emoji_candidate == emoji_candidate[emoji_set_regex]
177171
if strict_eaw
178172
res += self.of(emoji_candidate[0], ambiguous, emoji: false)
179173
else

0 commit comments

Comments
 (0)