本站源代码
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

44 líneas
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