aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings/strings.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-03-26 13:05:04 -0700
committerRobert Griesemer <gri@golang.org>2010-03-26 13:05:04 -0700
commitd0ffee8abfad42e632129848b1f8ab9efcfa6ce9 (patch)
tree3f9d9457659ce6a0c93d3b8fd966442b6043d467 /src/pkg/strings/strings.go
parent9e481e2905f5ddacf603fa2c0d9fc555c211f71b (diff)
downloadgo-d0ffee8abfad42e632129848b1f8ab9efcfa6ce9.tar.xz
bytes, strings: IndexOfAny
+ first use in go/doc R=r CC=golang-dev https://golang.org/cl/781041
Diffstat (limited to 'src/pkg/strings/strings.go')
-rw-r--r--src/pkg/strings/strings.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
index a8f3150c3e..1ceaeefbd4 100644
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -106,6 +106,21 @@ func LastIndex(s, sep string) int {
return -1
}
+// IndexAny returns the index of the first instance of any Unicode code point
+// from chars in s, or -1 if no Unicode code point from chars is present in s.
+func IndexAny(s, chars string) int {
+ if len(chars) > 0 {
+ for i, c := range s {
+ for _, m := range chars {
+ if c == m {
+ return i
+ }
+ }
+ }
+ }
+ return -1
+}
+
// Generic split: splits after each instance of sep,
// including sepSave bytes of sep in the subarrays.
func genSplit(s, sep string, sepSave, n int) []string {