diff options
| author | Robert Griesemer <gri@golang.org> | 2010-03-26 13:05:04 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2010-03-26 13:05:04 -0700 |
| commit | d0ffee8abfad42e632129848b1f8ab9efcfa6ce9 (patch) | |
| tree | 3f9d9457659ce6a0c93d3b8fd966442b6043d467 /src/pkg/strings/strings.go | |
| parent | 9e481e2905f5ddacf603fa2c0d9fc555c211f71b (diff) | |
| download | go-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.go | 15 |
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 { |
