Skip to content

Commit

Permalink
strings: clarify example of ContainsAny
Browse files Browse the repository at this point in the history
I have seen code that literally copied the example like this:

    if strings.ContainsAny(s, "1 & 2 & 3") {

The developer apparently thought that this is the way to
specify multiple characters and I noticed this pattern
being used in the example. Let's update the example so
that it's clear how multiple Unicode code points should
be specified.

Change-Id: Id4d780555e521af62fb787a7950be1e60848cd95
Reviewed-on: https://go-review.googlesource.com/c/go/+/178737
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
martin-sucha authored and bradfitz committed May 24, 2019
1 parent cd0f5f3 commit db32555
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/strings/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ func ExampleContains() {

func ExampleContainsAny() {
fmt.Println(strings.ContainsAny("team", "i"))
fmt.Println(strings.ContainsAny("failure", "u & i"))
fmt.Println(strings.ContainsAny("fail", "ui"))
fmt.Println(strings.ContainsAny("ure", "ui"))
fmt.Println(strings.ContainsAny("failure", "ui"))
fmt.Println(strings.ContainsAny("foo", ""))
fmt.Println(strings.ContainsAny("", ""))
// Output:
// false
// true
// true
// true
// false
// false
}
Expand Down

0 comments on commit db32555

Please sign in to comment.