mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes: add Contains function
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5349041
This commit is contained in:
parent
632a2c59b1
commit
1a4402a1fe
1 changed files with 5 additions and 0 deletions
|
|
@ -88,6 +88,11 @@ func Count(s, sep []byte) int {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contains returns whether subslice is within b.
|
||||||
|
func Contains(b, subslice []string) bool {
|
||||||
|
return Index(b, subslice) != -1
|
||||||
|
}
|
||||||
|
|
||||||
// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
|
// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
|
||||||
func Index(s, sep []byte) int {
|
func Index(s, sep []byte) int {
|
||||||
n := len(sep)
|
n := len(sep)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue