From 4c9cab3f8ae7b55f7124d7c3cf7ac6b4cc3db210 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 1 Mar 2020 12:36:02 +0900 Subject: 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 --- src/util/chars.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/util/chars.go') 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-- { -- cgit v1.2.3