diff --git a/fzf b/fzf index 978feaee..d226803a 100755 --- a/fzf +++ b/fzf @@ -155,12 +155,27 @@ class FZF (arr[2] || 0)].pack('U*') end + if String.method_defined?(:each_char) + def self.split str + str.each_char.to_a + end + else + def self.split str + str.split('') + end + end + def self.nfc str, offsets = [] ret = '' omap = [] pend = [] - str.split(//).each_with_index do |c, idx| - cp = c.ord + split(str).each_with_index do |c, idx| + cp = + begin + c.ord + rescue Exception + next + end omap << ret.length unless pend.empty? if cp >= JUNGSUNG && cp < JUNGSUNG + JUNGSUNGS @@ -221,9 +236,12 @@ class FZF def cursor_y; C.lines - 1; end def cprint str, col C.attron(col) do - C.addstr str.gsub("\0", '') + addstr_safe str end if str end + def addstr_safe str + C.addstr str.gsub("\0", '') + end def print_input C.setpos cursor_y, 0 @@ -320,7 +338,7 @@ class FZF cprint token, color(chosen ? :match! : :match, chosen) C.attron color(:chosen, true) if chosen else - C.addstr token + addstr_safe token end end C.attroff color(:chosen, true) if chosen diff --git a/test/test_fzf.rb b/test/test_fzf.rb index 2ea3f5a9..681db5fb 100644 --- a/test/test_fzf.rb +++ b/test/test_fzf.rb @@ -288,5 +288,10 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal NFD, nfd end end + + def test_split + assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"], + FZF::UConv.split("abc\xFFdef") + end end