aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings/strings.go
diff options
context:
space:
mode:
authorScott Lawrence <bytbox@gmail.com>2011-11-23 20:20:14 -0800
committerRob Pike <r@golang.org>2011-11-23 20:20:14 -0800
commit0f0c25dcccee52c4fae3b54ca8b185984ceff1f9 (patch)
treede04be060431ae0e246f895ffd224ffb3c42bcc9 /src/pkg/strings/strings.go
parentda62104169c7b31f8b2917b24232dd349b769c8f (diff)
downloadgo-0f0c25dcccee52c4fae3b54ca8b185984ceff1f9.tar.xz
strings: Add ContainsAny and ContainsRune to correspond to IndexAny etc.
R=golang-dev, r CC=golang-dev https://golang.org/cl/5430046
Diffstat (limited to 'src/pkg/strings/strings.go')
-rw-r--r--src/pkg/strings/strings.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
index b4d920714a..53fdeadf97 100644
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -64,7 +64,17 @@ func Count(s, sep string) int {
// Contains returns true if substr is within s.
func Contains(s, substr string) bool {
- return Index(s, substr) != -1
+ return Index(s, substr) >= 0
+}
+
+// ContainsAny returns true if any Unicode code points in chars are within s.
+func ContainsAny(s, chars string) bool {
+ return IndexAny(s, chars) >= 0
+}
+
+// ContainsRune returns true if the Unicode code point r is within s.
+func ContainsRune(s string, r rune) bool {
+ return IndexRune(s, r) >= 0
}
// Index returns the index of the first instance of sep in s, or -1 if sep is not present in s.
@@ -269,7 +279,7 @@ func FieldsFunc(s string, f func(rune) bool) []string {
fieldStart = i
}
}
- if fieldStart != -1 { // Last field might end at EOF.
+ if fieldStart >= 0 { // Last field might end at EOF.
a[na] = s[fieldStart:]
}
return a
@@ -512,7 +522,7 @@ func lastIndexFunc(s string, f func(rune) bool, truth bool) int {
}
func makeCutsetFunc(cutset string) func(rune) bool {
- return func(r rune) bool { return IndexRune(cutset, r) != -1 }
+ return func(r rune) bool { return IndexRune(cutset, r) >= 0 }
}
// Trim returns a slice of the string s with all leading and