diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-18 19:00:03 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-19 09:02:42 +1100 |
commit | ca7252ef8ee26affdc2c74f05c9c20196a8d571b (patch) | |
tree | 7323ca472558a435f01ae62e123cc2576e1959b3 /vendor/github.com/gobwas/glob/match/prefix_any.go | |
parent | a496858c629e3c6241b51cf99cd38d6fa1b787bc (diff) |
suggest files when picking a path to filter on
async fetching of suggestions
remove limit
cache the trie for future use
more
more
Diffstat (limited to 'vendor/github.com/gobwas/glob/match/prefix_any.go')
-rw-r--r-- | vendor/github.com/gobwas/glob/match/prefix_any.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/github.com/gobwas/glob/match/prefix_any.go b/vendor/github.com/gobwas/glob/match/prefix_any.go new file mode 100644 index 000000000..8ee58fe1b --- /dev/null +++ b/vendor/github.com/gobwas/glob/match/prefix_any.go @@ -0,0 +1,55 @@ +package match + +import ( + "fmt" + "strings" + "unicode/utf8" + + sutil "github.com/gobwas/glob/util/strings" +) + +type PrefixAny struct { + Prefix string + Separators []rune +} + +func NewPrefixAny(s string, sep []rune) PrefixAny { + return PrefixAny{s, sep} +} + +func (self PrefixAny) Index(s string) (int, []int) { + idx := strings.Index(s, self.Prefix) + if idx == -1 { + return -1, nil + } + + n := len(self.Prefix) + sub := s[idx+n:] + i := sutil.IndexAnyRunes(sub, self.Separators) + if i > -1 { + sub = sub[:i] + } + + seg := acquireSegments(len(sub) + 1) + seg = append(seg, n) + for i, r := range sub { + seg = append(seg, n+i+utf8.RuneLen(r)) + } + + return idx, seg +} + +func (self PrefixAny) Len() int { + return lenNo +} + +func (self PrefixAny) Match(s string) bool { + if !strings.HasPrefix(s, self.Prefix) { + return false + } + return sutil.IndexAnyRunes(s[len(self.Prefix):], self.Separators) == -1 +} + +func (self PrefixAny) String() string { + return fmt.Sprintf("<prefix_any:%s![%s]>", self.Prefix, string(self.Separators)) +} |