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

40 lines
563B

  1. package strings
  2. import (
  3. "strings"
  4. "unicode/utf8"
  5. )
  6. func IndexAnyRunes(s string, rs []rune) int {
  7. for _, r := range rs {
  8. if i := strings.IndexRune(s, r); i != -1 {
  9. return i
  10. }
  11. }
  12. return -1
  13. }
  14. func LastIndexAnyRunes(s string, rs []rune) int {
  15. for _, r := range rs {
  16. i := -1
  17. if 0 <= r && r < utf8.RuneSelf {
  18. i = strings.LastIndexByte(s, byte(r))
  19. } else {
  20. sub := s
  21. for len(sub) > 0 {
  22. j := strings.IndexRune(s, r)
  23. if j == -1 {
  24. break
  25. }
  26. i = j
  27. sub = sub[i+1:]
  28. }
  29. }
  30. if i != -1 {
  31. return i
  32. }
  33. }
  34. return -1
  35. }
上海开阖软件有限公司 沪ICP备12045867号-1