diff options
| author | hopehook <hopehook@qq.com> | 2023-01-03 16:23:16 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-01-24 22:06:45 +0000 |
| commit | 0b3f58c48e3298e49e27f80dc748f0652339d63e (patch) | |
| tree | b97cd822afb25332f99f90630c931a3d1ccc8f94 /src/bytes/bytes.go | |
| parent | 43f9b826c322d5541ca0260f8b0c9b71db0f7ec8 (diff) | |
| download | go-0b3f58c48e3298e49e27f80dc748f0652339d63e.tar.xz | |
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>
Diffstat (limited to 'src/bytes/bytes.go')
| -rw-r--r-- | src/bytes/bytes.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index e2e5d5fda7..ea8146c166 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -86,6 +86,11 @@ func ContainsRune(b []byte, r rune) bool { return IndexRune(b, r) >= 0 } +// ContainsFunc reports whether any of the UTF-8-encoded code points r within b satisfy f(r). +func ContainsFunc(b []byte, f func(rune) bool) bool { + return IndexFunc(b, f) >= 0 +} + // IndexByte returns the index of the first instance of c in b, or -1 if c is not present in b. func IndexByte(b []byte, c byte) int { return bytealg.IndexByte(b, c) |
