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

50 lines
791B

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