File: suffix.go

package info (click to toggle)
golang-github-gobwas-glob 0.2.3%2Bgit20180208.19c076c-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 364 kB
  • sloc: sh: 20; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 530 bytes parent folder | download | duplicates (4)
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
package match

import (
	"fmt"
	"strings"
)

type Suffix struct {
	Suffix string
}

func NewSuffix(s string) Suffix {
	return Suffix{s}
}

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

func (self Suffix) Match(s string) bool {
	return strings.HasSuffix(s, self.Suffix)
}

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

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

func (self Suffix) String() string {
	return fmt.Sprintf("<suffix:%s>", self.Suffix)
}