File: suffix_any.go

package info (click to toggle)
golang-github-gobwas-glob 0.2.3%2Bgit20181002.e7a84e9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 364 kB
  • sloc: sh: 20; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package match

import (
	"fmt"
	"strings"

	sutil "github.com/gobwas/glob/util/strings"
)

type SuffixAny struct {
	Suffix     string
	Separators []rune
}

func NewSuffixAny(s string, sep []rune) SuffixAny {
	return SuffixAny{s, sep}
}

func (self SuffixAny) Index(s string) (int, []int) {
	idx := strings.Index(s, self.Suffix)
	if idx == -1 {
		return -1, nil
	}

	i := sutil.LastIndexAnyRunes(s[:idx], self.Separators) + 1

	return i, []int{idx + len(self.Suffix) - i}
}

func (self SuffixAny) Len() int {
	return lenNo
}

func (self SuffixAny) Match(s string) bool {
	if !strings.HasSuffix(s, self.Suffix) {
		return false
	}
	return sutil.IndexAnyRunes(s[:len(s)-len(self.Suffix)], self.Separators) == -1
}

func (self SuffixAny) String() string {
	return fmt.Sprintf("<suffix_any:![%s]%s>", string(self.Separators), self.Suffix)
}