bytes, strings: add ContainsFunc

Fixes #54386.

Change-Id: I78747da337ed6129e4f7426dd0483a644bed82e3
Reviewed-on: https://go-review.googlesource.com/c/go/+/460216
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
hopehook 2023-01-03 16:23:16 +08:00 committed by Gopher Robot
parent 43f9b826c3
commit 0b3f58c48e
5 changed files with 34 additions and 0 deletions

View file

@ -69,6 +69,11 @@ func ContainsRune(s string, r rune) bool {
return IndexRune(s, r) >= 0
}
// ContainsFunc reports whether any Unicode code points r within s satisfy f(r).
func ContainsFunc(s string, f func(rune) bool) bool {
return IndexFunc(s, f) >= 0
}
// LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.
func LastIndex(s, substr string) int {
n := len(substr)