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

44 lines
726B

  1. package match
  2. import (
  3. "fmt"
  4. "github.com/gobwas/glob/util/runes"
  5. "unicode/utf8"
  6. )
  7. // single represents ?
  8. type Single struct {
  9. Separators []rune
  10. }
  11. func NewSingle(s []rune) Single {
  12. return Single{s}
  13. }
  14. func (self Single) Match(s string) bool {
  15. r, w := utf8.DecodeRuneInString(s)
  16. if len(s) > w {
  17. return false
  18. }
  19. return runes.IndexRune(self.Separators, r) == -1
  20. }
  21. func (self Single) Len() int {
  22. return lenOne
  23. }
  24. func (self Single) Index(s string) (int, []int) {
  25. for i, r := range s {
  26. if runes.IndexRune(self.Separators, r) == -1 {
  27. return i, segmentsByRuneLength[utf8.RuneLen(r)]
  28. }
  29. }
  30. return -1, nil
  31. }
  32. func (self Single) String() string {
  33. return fmt.Sprintf("<single:![%s]>", string(self.Separators))
  34. }
上海开阖软件有限公司 沪ICP备12045867号-1