mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes, strings: IndexOfAny
+ first use in go/doc R=r CC=golang-dev https://golang.org/cl/781041
This commit is contained in:
parent
9e481e2905
commit
d0ffee8abf
5 changed files with 102 additions and 28 deletions
|
|
@ -106,6 +106,21 @@ func LastIndex(s, sep string) int {
|
|||
return -1
|
||||
}
|
||||
|
||||
// IndexAny returns the index of the first instance of any Unicode code point
|
||||
// from chars in s, or -1 if no Unicode code point from chars is present in s.
|
||||
func IndexAny(s, chars string) int {
|
||||
if len(chars) > 0 {
|
||||
for i, c := range s {
|
||||
for _, m := range chars {
|
||||
if c == m {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Generic split: splits after each instance of sep,
|
||||
// including sepSave bytes of sep in the subarrays.
|
||||
func genSplit(s, sep string, sepSave, n int) []string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue