]> Cypherpunks repositories - gostls13.git/commitdiff
strings: Add IndexFunc example
authorRobin Eklind <r.eklind.87@gmail.com>
Mon, 16 Dec 2013 18:44:23 +0000 (10:44 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 16 Dec 2013 18:44:23 +0000 (10:44 -0800)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/42370043

src/pkg/strings/example_test.go

index 7350131b85fd07615ade000e5f65530340d9a4e0..62a9af74d00d5d2c6efb66aea5dbf7649cdbac4a 100644 (file)
@@ -68,6 +68,17 @@ func ExampleIndex() {
        // -1
 }
 
+func ExampleIndexFunc() {
+       f := func(c rune) bool {
+               return unicode.Is(unicode.Han, c)
+       }
+       fmt.Println(strings.IndexFunc("Hello, 世界", f))
+       fmt.Println(strings.IndexFunc("Hello, world", f))
+       // Output:
+       // 7
+       // -1
+}
+
 func ExampleIndexRune() {
        fmt.Println(strings.IndexRune("chicken", 'k'))
        fmt.Println(strings.IndexRune("chicken", 'd'))