diff options
Diffstat (limited to 'libgo/go/strings/strings.go')
-rw-r--r-- | libgo/go/strings/strings.go | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/libgo/go/strings/strings.go b/libgo/go/strings/strings.go index bfd0571..c547297 100644 --- a/libgo/go/strings/strings.go +++ b/libgo/go/strings/strings.go @@ -198,26 +198,40 @@ func genSplit(s, sep string, sepSave, n int) []string { return a[0 : na+1] } -// Split slices s into substrings separated by sep and returns a slice of +// SplitN slices s into substrings separated by sep and returns a slice of // the substrings between those separators. -// If sep is empty, Split splits after each UTF-8 sequence. +// If sep is empty, SplitN splits after each UTF-8 sequence. // The count determines the number of substrings to return: // n > 0: at most n substrings; the last substring will be the unsplit remainder. // n == 0: the result is nil (zero substrings) // n < 0: all substrings -func Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) } +func SplitN(s, sep string, n int) []string { return genSplit(s, sep, 0, n) } -// SplitAfter slices s into substrings after each instance of sep and +// SplitAfterN slices s into substrings after each instance of sep and // returns a slice of those substrings. -// If sep is empty, Split splits after each UTF-8 sequence. +// If sep is empty, SplitAfterN splits after each UTF-8 sequence. // The count determines the number of substrings to return: // n > 0: at most n substrings; the last substring will be the unsplit remainder. // n == 0: the result is nil (zero substrings) // n < 0: all substrings -func SplitAfter(s, sep string, n int) []string { +func SplitAfterN(s, sep string, n int) []string { return genSplit(s, sep, len(sep), n) } +// Split slices s into all substrings separated by sep and returns a slice of +// the substrings between those separators. +// If sep is empty, Split splits after each UTF-8 sequence. +// It is equivalent to SplitN with a count of -1. +func Split(s, sep string) []string { return genSplit(s, sep, 0, -1) } + +// SplitAfter slices s into all substrings after each instance of sep and +// returns a slice of those substrings. +// If sep is empty, SplitAfter splits after each UTF-8 sequence. +// It is equivalent to SplitAfterN with a count of -1. +func SplitAfter(s, sep string) []string { + return genSplit(s, sep, len(sep), -1) +} + // Fields splits the string s around each instance of one or more consecutive white space // characters, returning an array of substrings of s or an empty list if s contains only white space. func Fields(s string) []string { @@ -349,7 +363,6 @@ func Repeat(s string, count int) string { return string(b) } - // ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case. func ToUpper(s string) string { return Map(unicode.ToUpper, s) } |