From 3f0e6a5806aba76037d53476e991cce045de16e4 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 21 Apr 2015 22:10:14 +0900 Subject: Fix #209 - Invalid mutation of input on case conversion --- src/algo/algo.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/algo') diff --git a/src/algo/algo.go b/src/algo/algo.go index c1c07f3e..3d5edb09 100644 --- a/src/algo/algo.go +++ b/src/algo/algo.go @@ -42,10 +42,8 @@ func FuzzyMatch(caseSensitive bool, runes *[]rune, pattern []rune) (int, int) { // compiler as of now does not inline non-leaf functions.) if char >= 'A' && char <= 'Z' { char += 32 - (*runes)[index] = char } else if char > unicode.MaxASCII { char = unicode.To(unicode.LowerCase, char) - (*runes)[index] = char } } if char == pattern[pidx] { @@ -63,6 +61,13 @@ func FuzzyMatch(caseSensitive bool, runes *[]rune, pattern []rune) (int, int) { pidx-- for index := eidx - 1; index >= sidx; index-- { char := (*runes)[index] + if !caseSensitive { + if char >= 'A' && char <= 'Z' { + char += 32 + } else if char > unicode.MaxASCII { + char = unicode.To(unicode.LowerCase, char) + } + } if char == pattern[pidx] { if pidx--; pidx < 0 { sidx = index -- cgit v1.2.3