aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorcui fliter <imcusg@gmail.com>2023-10-08 16:42:26 +0800
committerGopher Robot <gobot@golang.org>2023-10-09 22:05:38 +0000
commit8f61fab61862e0c8f8bb8db968d14c262ff54d4c (patch)
tree205bc1193da89dfb2cbad09f265cb4bb6231b728 /src/bytes
parent1ce8a3f08170c81085a26165d6c4e1a058d1e0d6 (diff)
downloadgo-8f61fab61862e0c8f8bb8db968d14c262ff54d4c.tar.gz
go-8f61fab61862e0c8f8bb8db968d14c262ff54d4c.zip
bytes,strings: add example for ContainsFunc
Change-Id: I340e892aa4ecc780905be984016efc86699a45a2 Reviewed-on: https://go-review.googlesource.com/c/go/+/533556 Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/example_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/bytes/example_test.go b/src/bytes/example_test.go
index 20faf3e1f5..5a66b1e436 100644
--- a/src/bytes/example_test.go
+++ b/src/bytes/example_test.go
@@ -212,6 +212,17 @@ func ExampleContainsRune() {
// false
}
+func ExampleContainsFunc() {
+ f := func(r rune) bool {
+ return r >= 'a' && r <= 'z'
+ }
+ fmt.Println(bytes.ContainsFunc([]byte("HELLO"), f))
+ fmt.Println(bytes.ContainsFunc([]byte("World"), f))
+ // Output:
+ // false
+ // true
+}
+
func ExampleCount() {
fmt.Println(bytes.Count([]byte("cheese"), []byte("e")))
fmt.Println(bytes.Count([]byte("five"), []byte(""))) // before & after each rune