File: strings.go

package info (click to toggle)
golang-github-gobwas-glob 0.2.3%2Bgit20180208.19c076c-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 364 kB
  • sloc: sh: 20; makefile: 3
file content (39 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package strings

import (
	"strings"
	"unicode/utf8"
)

func IndexAnyRunes(s string, rs []rune) int {
	for _, r := range rs {
		if i := strings.IndexRune(s, r); i != -1 {
			return i
		}
	}

	return -1
}

func LastIndexAnyRunes(s string, rs []rune) int {
	for _, r := range rs {
		i := -1
		if 0 <= r && r < utf8.RuneSelf {
			i = strings.LastIndexByte(s, byte(r))
		} else {
			sub := s
			for len(sub) > 0 {
				j := strings.IndexRune(s, r)
				if j == -1 {
					break
				}
				i = j
				sub = sub[i+1:]
			}
		}
		if i != -1 {
			return i
		}
	}
	return -1
}