mirror of https://github.com/gobwas/glob.git
bugfix with row length
This commit is contained in:
parent
ce6abff517
commit
0354991b92
|
@ -105,6 +105,10 @@ func TestGlob(t *testing.T) {
|
|||
glob(true, "???", "abc"),
|
||||
glob(true, "?*?", "abc"),
|
||||
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,abcd}a", "abcda"),
|
||||
|
|
14
match/row.go
14
match/row.go
|
@ -45,12 +45,11 @@ func (self Row) lenOk(s string) bool {
|
|||
var i int
|
||||
for _ = range s {
|
||||
i++
|
||||
if i >= self.RunesLength {
|
||||
return true
|
||||
if i > self.RunesLength {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return self.RunesLength == i
|
||||
}
|
||||
|
||||
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) {
|
||||
if !self.lenOk(s) {
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
for i := range s {
|
||||
// this is not strict check but useful
|
||||
if len(s[i:]) < self.RunesLength {
|
||||
break
|
||||
}
|
||||
|
||||
if self.matchAll(s[i:]) {
|
||||
return i, self.Segments
|
||||
}
|
||||
}
|
||||
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue