Skip to content

Commit

Permalink
[ruby/reline] "Halfwidth char + halfwidth (han)dakuten" is a single g…
Browse files Browse the repository at this point in the history
…rapheme.

When a halfwidth character is followed by a halfwidth dakuten or a
halfwidth handakuten character, it should be treated as a single
grapheme.

ruby/reline@9f20b9ec28
  • Loading branch information
aycabta authored and matzbot committed Dec 23, 2021
1 parent daf4a88 commit 726cc81
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/reline/unicode.rb
Expand Up @@ -79,6 +79,8 @@ def self.escape_for_print(str)

require 'reline/unicode/east_asian_width'

HalfwidthDakutenHandakuten = /[\u{FF9E}\u{FF9F}]/

MBCharWidthRE = /
(?<width_2_1>
[#{ EscapedChars.map {|c| "\\x%02x" % c.ord }.join }] (?# ^ + char, such as ^M, ^H, ^[, ...)
Expand All @@ -93,6 +95,12 @@ def self.escape_for_print(str)
#{ EastAsianWidth::TYPE_H }
| #{ EastAsianWidth::TYPE_NA }
| #{ EastAsianWidth::TYPE_N }
)(?!#{ HalfwidthDakutenHandakuten })
| (?<width_2_3>
(?: #{ EastAsianWidth::TYPE_H }
| #{ EastAsianWidth::TYPE_NA }
| #{ EastAsianWidth::TYPE_N })
#{ HalfwidthDakutenHandakuten }
)
| (?<ambiguous_width>
#{EastAsianWidth::TYPE_A}
Expand All @@ -109,7 +117,7 @@ def self.get_mbchar_width(mbchar)
m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
case
when m.nil? then 1 # TODO should be U+FFFD � REPLACEMENT CHARACTER
when m[:width_2_1], m[:width_2_2] then 2
when m[:width_2_1], m[:width_2_2], m[:width_2_3] then 2
when m[:width_3] then 3
when m[:width_0] then 0
when m[:width_1] then 1
Expand Down

0 comments on commit 726cc81

Please sign in to comment.