summaryrefslogtreecommitdiff
path: root/src/util/chars.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-03-01 12:36:02 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-03-01 12:36:02 +0900
commit4c9cab3f8ae7b55f7124d7c3cf7ac6b4cc3db210 (patch)
tree4c0e59346708bfd82a15743d13a56480d245d45e /src/util/chars.go
parentb2c0413a98e210cedd34fbe0f6ba051906da398f (diff)
downloadfzf-4c9cab3f8ae7b55f7124d7c3cf7ac6b4cc3db210.tar.gz
Fix prefix/suffix/equal matcher to trim whitespaces
- Prefix matcher will trim leading whitespaces only when the pattern doesn't start with a whitespace - Suffix matcher will trim trailing whitespaces only when the pattern doesn't end with a whitespace - Equal matcher will trim leading whitespaces only when the pattern doesn't start with a whitespace, and trim trailing whitespaces only when the pattern doesn't end with a whitespace Previously, only suffix matcher would trim whitespaces unconditionally. Fix #1894
Diffstat (limited to 'src/util/chars.go')
-rw-r--r--src/util/chars.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util/chars.go b/src/util/chars.go
index a57ba4bb..41de9243 100644
--- a/src/util/chars.go
+++ b/src/util/chars.go
@@ -130,6 +130,18 @@ func (chars *Chars) TrimLength() uint16 {
return chars.trimLength
}
+func (chars *Chars) LeadingWhitespaces() int {
+ whitespaces := 0
+ for i := 0; i < chars.Length(); i++ {
+ char := chars.Get(i)
+ if !unicode.IsSpace(char) {
+ break
+ }
+ whitespaces++
+ }
+ return whitespaces
+}
+
func (chars *Chars) TrailingWhitespaces() int {
whitespaces := 0
for i := chars.Length() - 1; i >= 0; i-- {