You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
836 B

  1. package match
  2. import (
  3. "fmt"
  4. "strings"
  5. sutil "github.com/gobwas/glob/util/strings"
  6. )
  7. type SuffixAny struct {
  8. Suffix string
  9. Separators []rune
  10. }
  11. func NewSuffixAny(s string, sep []rune) SuffixAny {
  12. return SuffixAny{s, sep}
  13. }
  14. func (self SuffixAny) Index(s string) (int, []int) {
  15. idx := strings.Index(s, self.Suffix)
  16. if idx == -1 {
  17. return -1, nil
  18. }
  19. i := sutil.LastIndexAnyRunes(s[:idx], self.Separators) + 1
  20. return i, []int{idx + len(self.Suffix) - i}
  21. }
  22. func (self SuffixAny) Len() int {
  23. return lenNo
  24. }
  25. func (self SuffixAny) Match(s string) bool {
  26. if !strings.HasSuffix(s, self.Suffix) {
  27. return false
  28. }
  29. return sutil.IndexAnyRunes(s[:len(s)-len(self.Suffix)], self.Separators) == -1
  30. }
  31. func (self SuffixAny) String() string {
  32. return fmt.Sprintf("<suffix_any:![%s]%s>", string(self.Separators), self.Suffix)
  33. }