]> Cypherpunks.ru repositories - gostls13.git/commitdiff
bytes,strings: add example for ContainsFunc
authorcui fliter <imcusg@gmail.com>
Sun, 8 Oct 2023 08:42:26 +0000 (16:42 +0800)
committerGopher Robot <gobot@golang.org>
Mon, 9 Oct 2023 22:05:38 +0000 (22:05 +0000)
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>

src/bytes/example_test.go
src/strings/example_test.go

index 20faf3e1f5f6a32cedcbbb3767752afb40b0e15c..5a66b1e43695948fbad95d555181a57c52bcaf68 100644 (file)
@@ -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
index ab83e10de45de404bb49a22ca730b6cf3053658c..bdab7ae8dea9d638c7ba07c5a74db2a364b32f64 100644 (file)
@@ -80,6 +80,17 @@ func ExampleContainsRune() {
        // false
 }
 
+func ExampleContainsFunc() {
+       f := func(r rune) bool {
+               return r == 'a' || r == 'e' || r == 'i' || r == 'o' || r == 'u'
+       }
+       fmt.Println(strings.ContainsFunc("hello", f))
+       fmt.Println(strings.ContainsFunc("rhythms", f))
+       // Output:
+       // true
+       // false
+}
+
 func ExampleCount() {
        fmt.Println(strings.Count("cheese", "e"))
        fmt.Println(strings.Count("five", "")) // before & after each rune