-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings.go
36 lines (31 loc) · 1.33 KB
/
strings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package split
import (
"strings"
"unicode/utf8"
)
type StringIterator = Iterator[string]
var stringFuncs = funcs[string]{
index: strings.Index,
indexAny: strings.IndexAny,
decodeRune: utf8.DecodeRuneInString,
}
// String slices s into all substrings separated by sep.
//
// If s does not contain sep and sep is not empty, String returns a slice of length 1 whose only element is s.
//
// If sep is empty, String splits after each UTF-8 sequence. If both s and sep are empty, String returns an empty slice.
//
// String returns an iterator over substrings. Use [Iterator.Next] to loop, and [Iterator.Value] to get the current substring.
func String(s string, separator string) *StringIterator {
return split(s, separator, stringFuncs)
}
// StringAny slices s into all substrings separated by any Unicode code point in chars.
//
// If s does not contain any Unicode code point in chars, and chars is not empty, StringAny returns a slice of length 1 whose only element is s.
//
// If chars is empty, StringAny splits after each UTF-8 sequence. If both s and chars are empty, StringAny returns an empty slice.
//
// StringAny returns an iterator over substrings. Use [Iterator.Next] to loop, and [Iterator.Value] to get the current substrings.
func StringAny(s string, chars string) *StringIterator {
return splitAny(s, chars, stringFuncs)
}