bugfix with row length

This commit is contained in:
gobwas 2016-10-23 00:02:45 +03:00
parent ce6abff517
commit 0354991b92
2 changed files with 7 additions and 11 deletions

View File

@ -105,6 +105,10 @@ func TestGlob(t *testing.T) {
glob(true, "???", "abc"), glob(true, "???", "abc"),
glob(true, "?*?", "abc"), glob(true, "?*?", "abc"),
glob(true, "?*?", "ac"), glob(true, "?*?", "ac"),
glob(false, "sta", "stagnation"),
glob(true, "sta*", "stagnation"),
glob(false, "sta?", "stagnation"),
glob(false, "sta?n", "stagnation"),
glob(true, "{abc,def}ghi", "defghi"), glob(true, "{abc,def}ghi", "defghi"),
glob(true, "{abc,abcd}a", "abcda"), glob(true, "{abc,abcd}a", "abcda"),

View File

@ -45,12 +45,11 @@ func (self Row) lenOk(s string) bool {
var i int var i int
for _ = range s { for _ = range s {
i++ i++
if i >= self.RunesLength { if i > self.RunesLength {
return true
}
}
return false return false
}
}
return self.RunesLength == i
} }
func (self Row) Match(s string) bool { func (self Row) Match(s string) bool {
@ -62,21 +61,14 @@ func (self Row) Len() (l int) {
} }
func (self Row) Index(s string) (int, []int) { func (self Row) Index(s string) (int, []int) {
if !self.lenOk(s) {
return -1, nil
}
for i := range s { for i := range s {
// this is not strict check but useful
if len(s[i:]) < self.RunesLength { if len(s[i:]) < self.RunesLength {
break break
} }
if self.matchAll(s[i:]) { if self.matchAll(s[i:]) {
return i, self.Segments return i, self.Segments
} }
} }
return -1, nil return -1, nil
} }