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
|
|
@ -125,6 +125,21 @@ func LastIndex(s, sep []byte) int {
|
|||
return -1
|
||||
}
|
||||
|
||||
// IndexAny returns the index of the first instance of any byte
|
||||
// from bytes in s, or -1 if no byte from bytes is present in s.
|
||||
func IndexAny(s, bytes []byte) int {
|
||||
if len(bytes) > 0 {
|
||||
for i, b := range s {
|
||||
for _, m := range bytes {
|
||||
if b == 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 []byte, sepSave, n int) [][]byte {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue