diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2019-04-08 09:54:33 +0200 |
---|---|---|
committer | Tobias Klauser <tobias.klauser@gmail.com> | 2019-04-08 08:18:38 +0000 |
commit | f70d457a366a498ff91c4fb8dd03eca576b898bb (patch) | |
tree | eec2b2ab5a74884d84baabdd4086197070726604 /src/strings | |
parent | 20995f627422a3dce2039f06b5dfe1dc0ca174c6 (diff) | |
download | go-f70d457a366a498ff91c4fb8dd03eca576b898bb.tar.gz go-f70d457a366a498ff91c4fb8dd03eca576b898bb.zip |
strings: unindent Fields
CL 56470 unindented bytes.Fields, but not strings.Fields. Do so now to
make it easier to diff the two functions for potential differences.
Change-Id: Ifef81f50cee64e8277e91efa5ec5521d8d21d3bd
Reviewed-on: https://go-review.googlesource.com/c/go/+/170951
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/strings')
-rw-r--r-- | src/strings/strings.go | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/src/strings/strings.go b/src/strings/strings.go index e14fffb2b8..5a126a7a19 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -341,38 +341,38 @@ func Fields(s string) []string { wasSpace = isSpace } - if setBits < utf8.RuneSelf { // ASCII fast path - a := make([]string, n) - na := 0 - fieldStart := 0 - i := 0 - // Skip spaces in the front of the input. - for i < len(s) && asciiSpace[s[i]] != 0 { + if setBits >= utf8.RuneSelf { + // Some runes in the input string are not ASCII. + return FieldsFunc(s, unicode.IsSpace) + } + // ASCII fast path + a := make([]string, n) + na := 0 + fieldStart := 0 + i := 0 + // Skip spaces in the front of the input. + for i < len(s) && asciiSpace[s[i]] != 0 { + i++ + } + fieldStart = i + for i < len(s) { + if asciiSpace[s[i]] == 0 { i++ + continue } - fieldStart = i - for i < len(s) { - if asciiSpace[s[i]] == 0 { - i++ - continue - } - a[na] = s[fieldStart:i] - na++ + a[na] = s[fieldStart:i] + na++ + i++ + // Skip spaces in between fields. + for i < len(s) && asciiSpace[s[i]] != 0 { i++ - // Skip spaces in between fields. - for i < len(s) && asciiSpace[s[i]] != 0 { - i++ - } - fieldStart = i - } - if fieldStart < len(s) { // Last field might end at EOF. - a[na] = s[fieldStart:] } - return a + fieldStart = i } - - // Some runes in the input string are not ASCII. - return FieldsFunc(s, unicode.IsSpace) + if fieldStart < len(s) { // Last field might end at EOF. + a[na] = s[fieldStart:] + } + return a } // FieldsFunc splits the string s at each run of Unicode code points c satisfying f(c) |