Remove UTF-8 NFD conversion
Before adoption: this commit came in with the history the project adopted, so no landing records it.
We have iconv.
authored by Junegunn Choi · committed by Junegunn Choi · parent b0fdd6d · Browse files · 3 files·+15 added−170 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−170 removed
- tests:+1 added−48 removed
- other:+14 added−122 removed
Provenance
- Commit
edcd7c6- Tree
98ad35f- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
b0fdd6d
3 files changed+15 added−170 removed
modified:test/test_fzf.rb+1 added-48 removed
448 unmodified lines449 assert_equal 1, exact.match(list, "'-fuzzy", '', '').length450 assert_equal 2, exact.match(list, "-fuzzy", '', '').length451 end452 453- if RUBY_PLATFORM =~ /darwin/454- NFD = '한글'455- def test_nfc456- assert_equal 6, NFD.length457- assert_equal ["한글", [[0, 1], [1, 2]]],458- FZF::UConv.nfc(NFD, [[0, 3], [3, 6]])459-460- nfd2 = 'before' + NFD + 'after'461- assert_equal 6 + 6 + 5, nfd2.length462-463- nfc, offsets = FZF::UConv.nfc(nfd2, [[4, 14], [9, 13]])464- o1, o2 = offsets465- assert_equal 'before한글after', nfc466- assert_equal 're한글af', nfc[(o1.first...o1.last)]467- assert_equal '글a', nfc[(o2.first...o2.last)]468- end469-470- def test_nfd471- nfc = '한글'472- nfd = FZF::UConv.nfd(nfc)473- assert_equal 2, nfd.length474- assert_equal 6, nfd.join.length475- assert_equal NFD, nfd.join476- end477-478- def test_nfd_fuzzy_matcher479- matcher = FZF::FuzzyMatcher.new 0480- assert_equal [], matcher.match([NFD + NFD], '할', '', '')481- match = matcher.match([NFD + NFD], '글글', '', '')482- assert_equal [[NFD + NFD, [[3, 12]]]], match483- assert_equal ['한글한글', [[1, 4]]], FZF::UConv.nfc(*match.first)484- end485-486- def test_nfd_extended_fuzzy_matcher487- matcher = FZF::ExtendedFuzzyMatcher.new 0488- assert_equal [], matcher.match([NFD], "'글글", '', '')489- match = matcher.match([NFD], "'한글", '', '')490- assert_equal [[NFD, [[0, 6]]]], match491- assert_equal ['한글', [[0, 2]]], FZF::UConv.nfc(*match.first)492- end493- end494-495- def test_split496- assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"],497- FZF::UConv.split("abc\xFFdef")498- end499-453 # ^$ -> matches empty item454 def test_format_empty_item455 fzf = FZF.new []456 item = ['', [[0, 0]]]504- line, offsets = fzf.convert_item item457+ line, offsets = item458 tokens = fzf.format line, 80, offsets459 assert_equal [], tokens460 end461 162 unmodified linesmodified:fzf+7 added-122 removed
5 unmodified lines6 # / /_/_ / / /_7 # / __/ / /_/ __/8 # /_/ /___/_/ Fuzzy finder for your shell9 #10-# Version: 0.8.5 (May 21, 2014)10+# Version: 0.8.5 (May 29, 2014)11 #12 # Author: Junegunn Choi13 # URL: https://github.com/junegunn/fzf14 # License: MIT293 unmodified lines308 FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")] + $/ + $/309 exit x310 end311 312- case RUBY_PLATFORM313- when /darwin/314- module UConv315- CHOSUNG = 0x1100316- JUNGSUNG = 0x1161317- JONGSUNG = 0x11A7318- CHOSUNGS = 19319- JUNGSUNGS = 21320- JONGSUNGS = 28321- JJCOUNT = JUNGSUNGS * JONGSUNGS322- NFC_BEGIN = 0xAC00323- NFC_END = NFC_BEGIN + CHOSUNGS * JUNGSUNGS * JONGSUNGS324-325- def self.nfd str326- str.split(//).map do |c|327- cp = c.ord328- if cp >= NFC_BEGIN && cp < NFC_END329- chr = ''330- idx = cp - NFC_BEGIN331- cho = CHOSUNG + idx / JJCOUNT332- jung = JUNGSUNG + (idx % JJCOUNT) / JONGSUNGS333- jong = JONGSUNG + idx % JONGSUNGS334- chr << cho << jung335- chr << jong if jong != JONGSUNG336- chr337- else338- c339- end340- end341- end342-343- def self.to_nfc arr344- [NFC_BEGIN + arr[0] * JJCOUNT +345- (arr[1] || 0) * JONGSUNGS +346- (arr[2] || 0)].pack('U*')347- end348-349- if String.method_defined?(:each_char)350- def self.split str351- str.each_char.to_a352- end353- else354- def self.split str355- str.split('')356- end357- end358-359- def self.nfc str, offsets = []360- ret = ''361- omap = []362- pend = []363- split(str).each_with_index do |c, idx|364- cp =365- begin366- c.ord367- rescue Exception368- next369- end370- omap << ret.length371- unless pend.empty?372- if cp >= JUNGSUNG && cp < JUNGSUNG + JUNGSUNGS373- pend << cp - JUNGSUNG374- next375- elsif cp >= JONGSUNG && cp < JONGSUNG + JONGSUNGS376- pend << cp - JONGSUNG377- next378- else379- omap[-1] = omap[-1] + 1380- ret << to_nfc(pend)381- pend.clear382- end383- end384- if cp >= CHOSUNG && cp < CHOSUNG + CHOSUNGS385- pend << cp - CHOSUNG386- else387- ret << c388- end389- end390- ret << to_nfc(pend) unless pend.empty?391- return [ret,392- offsets.map { |pair|393- b, e = pair394- [omap[b] || 0, omap[e] || ((omap.last || 0) + 1)] }]395- end396- end397-398- def convert_item item399- UConv.nfc(*item)400- end401-402- class Matcher403- def query_chars q404- UConv.nfd(q)405- end406-407- def sanitize q408- UConv.nfd(q).join409- end410- end411- else412- def convert_item item413- item414- end415-416- class Matcher417- def query_chars q418- q.split(//)419- end420-421- def sanitize q422- q423- end424- end425- end426-312 def emit event313 @mtx.synchronize do314 @events[event] = yield315 @cv.broadcast360 unmodified lines676 next unless wipe || cleanse.include?(idx)677 row = cursor_y(idx + 2)678 chosen = idx == vcursor679 selected = @selects.include?([*item][0])795- line, offsets = convert_item item680+ line, offsets = item681 tokens = format line, maxc, offsets682 print_item row, tokens, chosen, selected683 end684 print_info375 unmodified lines1060 1061 def fuzzy_regex q1062 @regexp[q] ||= begin1063 q = q.downcase if @rxflag == Regexp::IGNORECASE1179- Regexp.new(query_chars(q).inject('') { |sum, e|1064+ Regexp.new(q.split(//).inject('') { |sum, e|1065 e = Regexp.escape e1066 sum << (e.length > 1 ? "(?:#{e}).*?" : # FIXME: not equivalent1067 "#{e}[^#{e}]*?")1068 }, rxflag_for(q))49 unmodified lines1118 case w1119 when ''1120 nil1121 when /^\^(.*)\$$/1237- Regexp.new('^' << sanitize(Regexp.escape($1)) << '$', rxflag_for(w))1122+ Regexp.new('^' << Regexp.escape($1) << '$', rxflag_for(w))1123 when /^'/1124 if @mode == :fuzzy && w.length > 11125 exact_regex w[1..-1]1126 elsif @mode == :exact1127 exact_regex w1128 end1129 when /^\^/1130 w.length > 1 ?1246- Regexp.new('^' << sanitize(Regexp.escape(w[1..-1])), rxflag_for(w)) : nil1131+ Regexp.new('^' << Regexp.escape(w[1..-1]), rxflag_for(w)) : nil1132 when /\$$/1133 w.length > 1 ?1249- Regexp.new(sanitize(Regexp.escape(w[0..-2])) << '$', rxflag_for(w)) : nil1134+ Regexp.new(Regexp.escape(w[0..-2]) << '$', rxflag_for(w)) : nil1135 else1136 @mode == :fuzzy ? fuzzy_regex(w) : exact_regex(w)1137 end, invert ]1138 }.select { |pair| pair.first }1139 end1140 1141 def exact_regex w1257- Regexp.new(sanitize(Regexp.escape(w)), rxflag_for(w))1142+ Regexp.new(Regexp.escape(w), rxflag_for(w))1143 end1144 1145 def match list, q, prefix, suffix1146 regexps = parse q28 unmodified linesmodified:README.md+7 added
547 unmodified lines548 fzf works on [Cygwin](http://www.cygwin.com/) and549 [MSYS2](http://sourceforge.net/projects/msys2/). You may need to use `--black`550 option on MSYS2 to avoid rendering issues.551 552+### Handling UTF-8 NFD paths on OSX553 554+Use iconv to convert NFD paths to NFC:555+556+```sh557+find . | iconv -f utf-8-mac -t utf8//ignore | fzf558+```559+560 License561 -------562 563 MIT6 unmodified lines