Skip to content

Commit bfb27fb

Browse files
committed
bytes,strings: document Fields trimming of leading and trailing characters
Fixes #72841 Change-Id: I46875c61e3147c69da759bf4bf4f0539cbd4f437 Reviewed-on: https://go-review.googlesource.com/c/go/+/658218 Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent fcb27f7 commit bfb27fb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/bytes/bytes.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,9 @@ var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}
451451
// Fields interprets s as a sequence of UTF-8-encoded code points.
452452
// It splits the slice s around each instance of one or more consecutive white space
453453
// characters, as defined by [unicode.IsSpace], returning a slice of subslices of s or an
454-
// empty slice if s contains only white space.
454+
// empty slice if s contains only white space. Every element of the returned slice is
455+
// non-empty. Unlike [Split], leading and trailing runs of white space characters
456+
// are discarded.
455457
func Fields(s []byte) [][]byte {
456458
// First count the fields.
457459
// This is an exact count if s is ASCII, otherwise it is an approximation.
@@ -505,7 +507,9 @@ func Fields(s []byte) [][]byte {
505507
// FieldsFunc interprets s as a sequence of UTF-8-encoded code points.
506508
// It splits the slice s at each run of code points c satisfying f(c) and
507509
// returns a slice of subslices of s. If all code points in s satisfy f(c), or
508-
// len(s) == 0, an empty slice is returned.
510+
// len(s) == 0, an empty slice is returned. Every element of the returned slice is
511+
// non-empty. Unlike [SplitFunc], leading and trailing runs of code points
512+
// satisfying f(c) are discarded.
509513
//
510514
// FieldsFunc makes no guarantees about the order in which it calls f(c)
511515
// and assumes that f always returns the same value for a given c.

src/strings/strings.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}
378378

379379
// Fields splits the string s around each instance of one or more consecutive white space
380380
// characters, as defined by [unicode.IsSpace], returning a slice of substrings of s or an
381-
// empty slice if s contains only white space.
381+
// empty slice if s contains only white space. Every element of the returned slice is
382+
// non-empty. Unlike [Split], leading and trailing runs runs of white space characters
383+
// are discarded.
382384
func Fields(s string) []string {
383385
// First count the fields.
384386
// This is an exact count if s is ASCII, otherwise it is an approximation.
@@ -430,7 +432,9 @@ func Fields(s string) []string {
430432

431433
// FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c)
432434
// and returns an array of slices of s. If all code points in s satisfy f(c) or the
433-
// string is empty, an empty slice is returned.
435+
// string is empty, an empty slice is returned. Every element of the returned slice is
436+
// non-empty. Unlike [SplitFunc], leading and trailing runs of code points satisfying f(c)
437+
// are discarded.
434438
//
435439
// FieldsFunc makes no guarantees about the order in which it calls f(c)
436440
// and assumes that f always returns the same value for a given c.

0 commit comments

Comments
 (0)