1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:54:39 -07:00

bytes, strings: mention the n < 0 case in Split/SplitAfter doc comment

R=r, rsc
CC=golang-dev
https://golang.org/cl/1669055
This commit is contained in:
Andrew Gerrand 2010-07-27 15:06:08 +10:00
parent 88fc337fa2
commit 8b821696cc
2 changed files with 28 additions and 17 deletions

View File

@ -179,17 +179,22 @@ func genSplit(s, sep []byte, sepSave, n int) [][]byte {
return a[0 : na+1] return a[0 : na+1]
} }
// Split splits the array s around each instance of sep, returning an array of subarrays of s. // Split slices s into subslices separated by sep and returns a slice of
// If sep is empty, Split splits s after each UTF-8 sequence. // the subslices between those separators.
// If n >= 0, Split splits s into at most n subarrays; the last subarray will contain an unsplit remainder. // If sep is empty, Split splits after each UTF-8 sequence.
// Thus if n == 0, the result will be nil. // The count determines the number of subslices to return:
// n > 0: at most n subslices; the last subslice will be the unsplit remainder.
// n == 0: the result is nil (zero subslices)
// n < 0: all subslices
func Split(s, sep []byte, n int) [][]byte { return genSplit(s, sep, 0, n) } func Split(s, sep []byte, n int) [][]byte { return genSplit(s, sep, 0, n) }
// SplitAfter splits the array s after each instance of sep, returning an array of subarrays of s. // SplitAfter slices s into subslices after each instance of sep and
// If sep is empty, SplitAfter splits s after each UTF-8 sequence. // returns a slice of those subslices.
// If n >= 0, SplitAfter splits s into at most n subarrays; the last subarray will contain an // If sep is empty, Split splits after each UTF-8 sequence.
// unsplit remainder. // The count determines the number of subslices to return:
// Thus if n == 0, the result will ne nil. // n > 0: at most n subslices; the last subslice will be the unsplit remainder.
// n == 0: the result is nil (zero subslices)
// n < 0: all subslices
func SplitAfter(s, sep []byte, n int) [][]byte { func SplitAfter(s, sep []byte, n int) [][]byte {
return genSplit(s, sep, len(sep), n) return genSplit(s, sep, len(sep), n)
} }

View File

@ -163,16 +163,22 @@ func genSplit(s, sep string, sepSave, n int) []string {
return a[0 : na+1] return a[0 : na+1]
} }
// Split splits the string s around each instance of sep, returning an array of substrings of s. // Split slices s into substrings separated by sep and returns a slice of
// If sep is empty, Split splits s after each UTF-8 sequence. // the substrings between those separators.
// If n >= 0, Split splits s into at most n substrings; the last substring will be the unsplit remainder. // If sep is empty, Split splits after each UTF-8 sequence.
// Thus if n == 0, the result will be nil. // 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 Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) }
// SplitAfter splits the string s after each instance of sep, returning an array of substrings of s. // SplitAfter slices s into substrings after each instance of sep and
// If sep is empty, SplitAfter splits s after each UTF-8 sequence. // returns a slice of those substrings.
// If n >= 0, SplitAfter splits s into at most n substrings; the last substring will be the unsplit remainder. // If sep is empty, Split splits after each UTF-8 sequence.
// Thus if n == 0, the result will be nil. // 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 SplitAfter(s, sep string, n int) []string {
return genSplit(s, sep, len(sep), n) return genSplit(s, sep, len(sep), n)
} }