From 04492bab10aeb0d081eeb8806792ccb77a8c5cb6 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Thu, 29 Sep 2016 22:40:22 +0900 Subject: [PATCH] Use unicode.IsSpace to cover more whitespace characters --- src/result.go | 3 ++- src/util/chars.go | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/result.go b/src/result.go index 9152f67..bc1deb4 100644 --- a/src/result.go +++ b/src/result.go @@ -3,6 +3,7 @@ package fzf import ( "math" "sort" + "unicode" "github.com/junegunn/fzf/src/curses" "github.com/junegunn/fzf/src/util" @@ -62,7 +63,7 @@ func buildResult(item *Item, offsets []Offset, score int, trimLen int) *Result { for idx := 0; idx < numChars; idx++ { r := item.text.Get(idx) whitePrefixLen = idx - if idx == minBegin || r != ' ' && r != '\t' { + if idx == minBegin || !unicode.IsSpace(r) { break } } diff --git a/src/util/chars.go b/src/util/chars.go index 12417c6..061120e 100644 --- a/src/util/chars.go +++ b/src/util/chars.go @@ -1,6 +1,7 @@ package util import ( + "unicode" "unicode/utf8" ) @@ -63,7 +64,7 @@ func (chars *Chars) TrimLength() int { len := chars.Length() for i = len - 1; i >= 0; i-- { char := chars.Get(i) - if char != ' ' && char != '\t' { + if !unicode.IsSpace(char) { break } } @@ -75,7 +76,7 @@ func (chars *Chars) TrimLength() int { var j int for j = 0; j < len; j++ { char := chars.Get(j) - if char != ' ' && char != '\t' { + if !unicode.IsSpace(char) { break } } @@ -86,7 +87,7 @@ func (chars *Chars) TrailingWhitespaces() int { whitespaces := 0 for i := chars.Length() - 1; i >= 0; i-- { char := chars.Get(i) - if char != ' ' && char != '\t' { + if !unicode.IsSpace(char) { break } whitespaces++