diff options
| author | Sean Liao <sean@liao.dev> | 2025-03-17 15:21:39 +0000 |
|---|---|---|
| committer | Sean Liao <sean@liao.dev> | 2025-03-18 15:12:18 -0700 |
| commit | bfb27fb36f2f651eb52e3f2ff20542f4302359ce (patch) | |
| tree | 41656af44ebaf04bc46fb759e4048a943824bdb2 /src/strings/strings.go | |
| parent | fcb27f717b0eccb2a3de1bc05a7d222325ad5aeb (diff) | |
| download | go-bfb27fb36f2f651eb52e3f2ff20542f4302359ce.tar.xz | |
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 <adonovan@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/strings/strings.go')
| -rw-r--r-- | src/strings/strings.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/strings/strings.go b/src/strings/strings.go index 7eb2de635c..fb53b59f2c 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -378,7 +378,9 @@ var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1} // Fields splits the string s around each instance of one or more consecutive white space // characters, as defined by [unicode.IsSpace], returning a slice of substrings of s or an -// empty slice if s contains only white space. +// empty slice if s contains only white space. Every element of the returned slice is +// non-empty. Unlike [Split], leading and trailing runs runs of white space characters +// are discarded. func Fields(s string) []string { // First count the fields. // This is an exact count if s is ASCII, otherwise it is an approximation. @@ -430,7 +432,9 @@ func Fields(s string) []string { // FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) // and returns an array of slices of s. If all code points in s satisfy f(c) or the -// string is empty, an empty slice is returned. +// string is empty, an empty slice is returned. Every element of the returned slice is +// non-empty. Unlike [SplitFunc], leading and trailing runs of code points satisfying f(c) +// are discarded. // // FieldsFunc makes no guarantees about the order in which it calls f(c) // and assumes that f always returns the same value for a given c. |
