1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] "Halfwidth char + halfwidth (han)dakuten" is a single grapheme.

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

https://github.com/ruby/reline/commit/9f20b9ec28
This commit is contained in:
aycabta 2021-12-23 23:08:37 +09:00 committed by git
parent daf4a8884b
commit 726cc8122e

View file

@ -79,6 +79,8 @@ class Reline::Unicode
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, ^[, ...)
@ -93,6 +95,12 @@ class Reline::Unicode
#{ 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}
@ -109,7 +117,7 @@ class Reline::Unicode
m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
case
when m.nil? then 1 # TODO should be U+FFFD <20> 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