summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2013-11-17 12:32:38 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2013-11-17 12:32:38 +0900
commit423e26b0c923ef5fc228fb82a293aec9bdc138b7 (patch)
tree101708a93b85587e97a950bad97d504568571b79
parent84921df0e35c49a976178b869b167b0d43dac675 (diff)
Better handling of NFD chars0.4.2
-rwxr-xr-xfzf37
-rw-r--r--fzf.gemspec2
-rw-r--r--test/test_fzf.rb16
3 files changed, 30 insertions, 25 deletions
diff --git a/fzf b/fzf
index 733b12c0..cbfbc1a7 100755
--- a/fzf
+++ b/fzf
@@ -137,21 +137,21 @@ class FZF
NFC_END = NFC_BEGIN + CHOSUNGS * JUNGSUNGS * JONGSUNGS
def self.nfd str
- ret = ''
- str.split(//).each do |c|
+ str.split(//).map do |c|
cp = c.ord
if cp >= NFC_BEGIN && cp < NFC_END
+ chr = ''
idx = cp - NFC_BEGIN
cho = CHOSUNG + idx / JJCOUNT
jung = JUNGSUNG + (idx % JJCOUNT) / JONGSUNGS
jong = JONGSUNG + idx % JONGSUNGS
- ret << cho << jung
- ret << jong if jong != JONGSUNG
+ chr << cho << jung
+ chr << jong if jong != JONGSUNG
+ chr
else
- ret << c
+ c
end
end
- ret
end
def self.to_nfc arr
@@ -215,16 +215,14 @@ class FZF
class Matcher
def query_chars q
- UConv.nfd(q).split(//)
+ UConv.nfd(q)
end
- end
- else
- module UConv
- def self.nfd str
- str
+
+ def sanitize q
+ UConv.nfd(q).join
end
end
-
+ else
def convert_item item
item
end
@@ -233,6 +231,10 @@ class FZF
def query_chars q
q.split(//)
end
+
+ def sanitize q
+ q
+ end
end
end
@@ -755,7 +757,8 @@ class FZF
q = q.downcase if @rxflag != 0
Regexp.new(query_chars(q).inject('') { |sum, e|
e = Regexp.escape e
- sum << "#{e}[^#{e}]*?"
+ sum << (e.length > 1 ? "(?:#{e}).*?" : # FIXME: not equivalent
+ "#{e}[^#{e}]*?")
}, @rxflag)
end
end
@@ -810,13 +813,13 @@ class FZF
nil
when /^'/
w.length > 1 ?
- Regexp.new(UConv.nfd(Regexp.escape(w[1..-1])), rxflag) : nil
+ Regexp.new(sanitize(Regexp.escape(w[1..-1])), rxflag) : nil
when /^\^/
w.length > 1 ?
- Regexp.new('^' << UConv.nfd(Regexp.escape(w[1..-1])), rxflag) : nil
+ Regexp.new('^' << sanitize(Regexp.escape(w[1..-1])), rxflag) : nil
when /\$$/
w.length > 1 ?
- Regexp.new(UConv.nfd(Regexp.escape(w[0..-2])) << '$', rxflag) : nil
+ Regexp.new(sanitize(Regexp.escape(w[0..-2])) << '$', rxflag) : nil
else
fuzzy_regex w
end, invert ]
diff --git a/fzf.gemspec b/fzf.gemspec
index a6845df4..aaefff1c 100644
--- a/fzf.gemspec
+++ b/fzf.gemspec
@@ -1,7 +1,7 @@
# coding: utf-8
Gem::Specification.new do |spec|
spec.name = 'fzf'
- spec.version = '0.4.1'
+ spec.version = '0.4.2'
spec.authors = ['Junegunn Choi']
spec.email = ['junegunn.c@gmail.com']
spec.description = %q{Fuzzy finder for your shell}
diff --git a/test/test_fzf.rb b/test/test_fzf.rb
index 7d0f4476..76a31352 100644
--- a/test/test_fzf.rb
+++ b/test/test_fzf.rb
@@ -293,21 +293,23 @@ class TestFZF < MiniTest::Unit::TestCase
def test_nfd
nfc = '한글'
nfd = FZF::UConv.nfd(nfc)
- assert_equal 6, nfd.length
- assert_equal NFD, nfd
+ assert_equal 2, nfd.length
+ assert_equal 6, nfd.join.length
+ assert_equal NFD, nfd.join
end
def test_nfd_fuzzy_matcher
matcher = FZF::FuzzyMatcher.new 0
- match = matcher.match([NFD], '할', '', '')
- assert_equal [[NFD, [[0, 6]]]], match
- assert_equal ['한글', [[0, 2]]], FZF::UConv.nfc(*match.first)
+ assert_equal [], matcher.match([NFD + NFD], '할', '', '')
+ match = matcher.match([NFD + NFD], '글글', '', '')
+ assert_equal [[NFD + NFD, [[3, 12]]]], match
+ assert_equal ['한글한글', [[1, 4]]], FZF::UConv.nfc(*match.first)
end
def test_nfd_extended_fuzzy_matcher
matcher = FZF::ExtendedFuzzyMatcher.new 0
- assert_equal [], matcher.match([NFD], "'할", '', '')
- match = matcher.match([NFD], "'한글", '', '')
+ assert_equal [], matcher.match([NFD], "'글글", '', '')
+ match = matcher.match([NFD], "'한글", '', '')
assert_equal [[NFD, [[0, 6]]]], match
assert_equal ['한글', [[0, 2]]], FZF::UConv.nfc(*match.first)
end