本站源代码
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.

36 lines
530B

  1. package match
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type Suffix struct {
  7. Suffix string
  8. }
  9. func NewSuffix(s string) Suffix {
  10. return Suffix{s}
  11. }
  12. func (self Suffix) Len() int {
  13. return lenNo
  14. }
  15. func (self Suffix) Match(s string) bool {
  16. return strings.HasSuffix(s, self.Suffix)
  17. }
  18. func (self Suffix) Index(s string) (int, []int) {
  19. idx := strings.Index(s, self.Suffix)
  20. if idx == -1 {
  21. return -1, nil
  22. }
  23. return 0, []int{idx + len(self.Suffix)}
  24. }
  25. func (self Suffix) String() string {
  26. return fmt.Sprintf("<suffix:%s>", self.Suffix)
  27. }
上海开阖软件有限公司 沪ICP备12045867号-1