strings.Split: make the default to split all.
Change the signature of Split to have no count,
assuming a full split, and rename the existing
Split with a count to SplitN.
Do the same to package bytes.
Add a gofix module.
R=adg, dsymonds, alex.brainman, rsc
CC=golang-dev
https://golang.org/cl/4661051
diff --git a/src/pkg/asn1/common.go b/src/pkg/asn1/common.go
index 9db887e..854f4da 100644
--- a/src/pkg/asn1/common.go
+++ b/src/pkg/asn1/common.go
@@ -83,7 +83,7 @@
// parseFieldParameters will parse it into a fieldParameters structure,
// ignoring unknown parts of the string.
func parseFieldParameters(str string) (ret fieldParameters) {
- for _, part := range strings.Split(str, ",", -1) {
+ for _, part := range strings.Split(str, ",") {
switch {
case part == "optional":
ret.optional = true
diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go
index 0f9ac98..3cec60f 100644
--- a/src/pkg/bytes/bytes.go
+++ b/src/pkg/bytes/bytes.go
@@ -212,24 +212,38 @@
return a[0 : na+1]
}
-// Split slices s into subslices separated by sep and returns a slice of
+// SplitN slices s into subslices separated by sep and returns a slice of
+// the subslices between those separators.
+// If sep is empty, SplitN splits after each UTF-8 sequence.
+// 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 SplitN(s, sep []byte, n int) [][]byte { return genSplit(s, sep, 0, n) }
+
+// SplitAfterN slices s into subslices after each instance of sep and
+// returns a slice of those subslices.
+// If sep is empty, SplitAfterN splits after each UTF-8 sequence.
+// 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 SplitAfterN(s, sep []byte, n int) [][]byte {
+ return genSplit(s, sep, len(sep), n)
+}
+
+// Split slices s into all subslices separated by sep and returns a slice of
// the subslices between those separators.
// If sep is empty, Split splits after each UTF-8 sequence.
-// 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) }
+// It is equivalent to SplitN with a count of -1.
+func Split(s, sep []byte) [][]byte { return genSplit(s, sep, 0, -1) }
-// SplitAfter slices s into subslices after each instance of sep and
+// SplitAfter slices s into all subslices after each instance of sep and
// returns a slice of those subslices.
-// If sep is empty, Split splits after each UTF-8 sequence.
-// 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 SplitAfter(s, sep []byte, n int) [][]byte {
- return genSplit(s, sep, len(sep), n)
+// 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 []byte) [][]byte {
+ return genSplit(s, sep, len(sep), -1)
}
// Fields splits the array s around each instance of one or more consecutive white space
diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go
index 4ce291a..7539353 100644
--- a/src/pkg/bytes/bytes_test.go
+++ b/src/pkg/bytes/bytes_test.go
@@ -6,6 +6,7 @@
import (
. "bytes"
+ "reflect"
"testing"
"unicode"
"utf8"
@@ -315,7 +316,7 @@
func TestExplode(t *testing.T) {
for _, tt := range explodetests {
- a := Split([]byte(tt.s), nil, tt.n)
+ a := SplitN([]byte(tt.s), nil, tt.n)
result := arrayOfString(a)
if !eq(result, tt.a) {
t.Errorf(`Explode("%s", %d) = %v; want %v`, tt.s, tt.n, result, tt.a)
@@ -354,7 +355,7 @@
func TestSplit(t *testing.T) {
for _, tt := range splittests {
- a := Split([]byte(tt.s), []byte(tt.sep), tt.n)
+ a := SplitN([]byte(tt.s), []byte(tt.sep), tt.n)
result := arrayOfString(a)
if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
@@ -367,6 +368,12 @@
if string(s) != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
}
+ if tt.n < 0 {
+ b := Split([]byte(tt.s), []byte(tt.sep))
+ if !reflect.DeepEqual(a, b) {
+ t.Errorf("Split disagrees withSplitN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
+ }
+ }
}
}
@@ -388,7 +395,7 @@
func TestSplitAfter(t *testing.T) {
for _, tt := range splitaftertests {
- a := SplitAfter([]byte(tt.s), []byte(tt.sep), tt.n)
+ a := SplitAfterN([]byte(tt.s), []byte(tt.sep), tt.n)
result := arrayOfString(a)
if !eq(result, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, result, tt.a)
@@ -398,6 +405,12 @@
if string(s) != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
}
+ if tt.n < 0 {
+ b := SplitAfter([]byte(tt.s), []byte(tt.sep))
+ if !reflect.DeepEqual(a, b) {
+ t.Errorf("SplitAfter disagrees withSplitAfterN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
+ }
+ }
}
}
diff --git a/src/pkg/compress/lzw/reader_test.go b/src/pkg/compress/lzw/reader_test.go
index 72121a6..f8042b0 100644
--- a/src/pkg/compress/lzw/reader_test.go
+++ b/src/pkg/compress/lzw/reader_test.go
@@ -84,7 +84,7 @@
func TestReader(t *testing.T) {
b := bytes.NewBuffer(nil)
for _, tt := range lzwTests {
- d := strings.Split(tt.desc, ";", -1)
+ d := strings.Split(tt.desc, ";")
var order Order
switch d[1] {
case "LSB":
diff --git a/src/pkg/crypto/x509/verify.go b/src/pkg/crypto/x509/verify.go
index 9145880..20a8157 100644
--- a/src/pkg/crypto/x509/verify.go
+++ b/src/pkg/crypto/x509/verify.go
@@ -202,8 +202,8 @@
return false
}
- patternParts := strings.Split(pattern, ".", -1)
- hostParts := strings.Split(host, ".", -1)
+ patternParts := strings.Split(pattern, ".")
+ hostParts := strings.Split(host, ".")
if len(patternParts) != len(hostParts) {
return false
diff --git a/src/pkg/debug/proc/proc_linux.go b/src/pkg/debug/proc/proc_linux.go
index 5831b0e..7ec7971 100644
--- a/src/pkg/debug/proc/proc_linux.go
+++ b/src/pkg/debug/proc/proc_linux.go
@@ -1229,7 +1229,7 @@
return err
}
- statParts := strings.Split(string(statFile), " ", 4)
+ statParts := strings.SplitN(string(statFile), " ", 4)
if len(statParts) > 2 && statParts[2] == "Z" {
// tid is a zombie
p.logTrace("thread %d is a zombie", tid)
diff --git a/src/pkg/exec/exec_test.go b/src/pkg/exec/exec_test.go
index c45a7d7..f6cebb9 100644
--- a/src/pkg/exec/exec_test.go
+++ b/src/pkg/exec/exec_test.go
@@ -55,7 +55,7 @@
t.Errorf("expected Waitmsg from cat combined; got %T: %v", err, err)
}
s := string(bs)
- sp := strings.Split(s, "\n", 2)
+ sp := strings.SplitN(s, "\n", 2)
if len(sp) != 2 {
t.Fatalf("expected two lines from cat; got %q", s)
}
diff --git a/src/pkg/exec/lp_plan9.go b/src/pkg/exec/lp_plan9.go
index c4e2a7a..e4751a4 100644
--- a/src/pkg/exec/lp_plan9.go
+++ b/src/pkg/exec/lp_plan9.go
@@ -42,7 +42,7 @@
}
path := os.Getenv("path")
- for _, dir := range strings.Split(path, "\000", -1) {
+ for _, dir := range strings.Split(path, "\000") {
if err := findExecutable(dir + "/" + file); err == nil {
return dir + "/" + file, nil
}
diff --git a/src/pkg/exec/lp_unix.go b/src/pkg/exec/lp_unix.go
index cdf7207..008fb11 100644
--- a/src/pkg/exec/lp_unix.go
+++ b/src/pkg/exec/lp_unix.go
@@ -39,7 +39,7 @@
return "", &Error{file, err}
}
pathenv := os.Getenv("PATH")
- for _, dir := range strings.Split(pathenv, ":", -1) {
+ for _, dir := range strings.Split(pathenv, ":") {
if dir == "" {
// Unix shell semantics: path element "" means "."
dir = "."
diff --git a/src/pkg/exec/lp_windows.go b/src/pkg/exec/lp_windows.go
index 4776345..7581088 100644
--- a/src/pkg/exec/lp_windows.go
+++ b/src/pkg/exec/lp_windows.go
@@ -47,7 +47,7 @@
x = `.COM;.EXE;.BAT;.CMD`
}
exts := []string{}
- for _, e := range strings.Split(strings.ToLower(x), `;`, -1) {
+ for _, e := range strings.Split(strings.ToLower(x), `;`) {
if e == "" {
continue
}
@@ -67,7 +67,7 @@
return
}
} else {
- for _, dir := range strings.Split(pathenv, `;`, -1) {
+ for _, dir := range strings.Split(pathenv, `;`) {
if f, err = findExecutable(dir+`\`+file, exts); err == nil {
return
}
diff --git a/src/pkg/exp/ogle/cmd.go b/src/pkg/exp/ogle/cmd.go
index a8db523..ff0d24c 100644
--- a/src/pkg/exp/ogle/cmd.go
+++ b/src/pkg/exp/ogle/cmd.go
@@ -154,7 +154,7 @@
}
println("Attached to", pid)
} else {
- parts := strings.Split(path, " ", -1)
+ parts := strings.Split(path, " ")
if len(parts) == 0 {
fname = ""
} else {
diff --git a/src/pkg/go/ast/print_test.go b/src/pkg/go/ast/print_test.go
index 0820dcfc..30b396f 100644
--- a/src/pkg/go/ast/print_test.go
+++ b/src/pkg/go/ast/print_test.go
@@ -53,7 +53,7 @@
// Split s into lines, trim whitespace from all lines, and return
// the concatenated non-empty lines.
func trim(s string) string {
- lines := strings.Split(s, "\n", -1)
+ lines := strings.Split(s, "\n")
i := 0
for _, line := range lines {
line = strings.TrimSpace(line)
diff --git a/src/pkg/go/build/dir.go b/src/pkg/go/build/dir.go
index 20f8f29..e0000b5 100644
--- a/src/pkg/go/build/dir.go
+++ b/src/pkg/go/build/dir.go
@@ -139,7 +139,7 @@
if dot := strings.Index(filename, "."); dot != -1 {
filename = filename[:dot]
}
- l := strings.Split(filename, "_", -1)
+ l := strings.Split(filename, "_")
n := len(l)
if n == 0 {
return true
diff --git a/src/pkg/go/doc/comment.go b/src/pkg/go/doc/comment.go
index f1ebfa9..85640af 100644
--- a/src/pkg/go/doc/comment.go
+++ b/src/pkg/go/doc/comment.go
@@ -58,7 +58,7 @@
}
// Split on newlines.
- cl := strings.Split(c, "\n", -1)
+ cl := strings.Split(c, "\n")
// Walk lines, stripping trailing white space and adding to list.
for _, l := range cl {
diff --git a/src/pkg/html/token_test.go b/src/pkg/html/token_test.go
index c17b436..c794612 100644
--- a/src/pkg/html/token_test.go
+++ b/src/pkg/html/token_test.go
@@ -161,7 +161,7 @@
loop:
for _, tt := range tokenTests {
z := NewTokenizer(bytes.NewBuffer([]byte(tt.html)))
- for i, s := range strings.Split(tt.golden, "$", -1) {
+ for i, s := range strings.Split(tt.golden, "$") {
if z.Next() == ErrorToken {
t.Errorf("%s token %d: want %q got error %v", tt.desc, i, s, z.Error())
continue loop
diff --git a/src/pkg/http/cgi/host.go b/src/pkg/http/cgi/host.go
index 2be3ede..01a9416 100644
--- a/src/pkg/http/cgi/host.go
+++ b/src/pkg/http/cgi/host.go
@@ -197,7 +197,7 @@
if len(line) == 0 {
break
}
- parts := strings.Split(string(line), ":", 2)
+ parts := strings.SplitN(string(line), ":", 2)
if len(parts) < 2 {
h.printf("cgi: bogus header line: %s", string(line))
continue
diff --git a/src/pkg/http/cgi/host_test.go b/src/pkg/http/cgi/host_test.go
index bbdb715..3b9dad5 100644
--- a/src/pkg/http/cgi/host_test.go
+++ b/src/pkg/http/cgi/host_test.go
@@ -46,7 +46,7 @@
}
linesRead++
trimmedLine := strings.TrimRight(line, "\r\n")
- split := strings.Split(trimmedLine, "=", 2)
+ split := strings.SplitN(trimmedLine, "=", 2)
if len(split) != 2 {
t.Fatalf("Unexpected %d parts from invalid line number %v: %q; existing map=%v",
len(split), linesRead, line, m)
diff --git a/src/pkg/http/cookie.go b/src/pkg/http/cookie.go
index 79c239b..fe70431 100644
--- a/src/pkg/http/cookie.go
+++ b/src/pkg/http/cookie.go
@@ -41,7 +41,7 @@
func readSetCookies(h Header) []*Cookie {
cookies := []*Cookie{}
for _, line := range h["Set-Cookie"] {
- parts := strings.Split(strings.TrimSpace(line), ";", -1)
+ parts := strings.Split(strings.TrimSpace(line), ";")
if len(parts) == 1 && parts[0] == "" {
continue
}
@@ -175,7 +175,7 @@
}
for _, line := range lines {
- parts := strings.Split(strings.TrimSpace(line), ";", -1)
+ parts := strings.Split(strings.TrimSpace(line), ";")
if len(parts) == 1 && parts[0] == "" {
continue
}
diff --git a/src/pkg/http/fs.go b/src/pkg/http/fs.go
index 139fe2c..0b83005 100644
--- a/src/pkg/http/fs.go
+++ b/src/pkg/http/fs.go
@@ -259,7 +259,7 @@
return nil, os.NewError("invalid range")
}
var ranges []httpRange
- for _, ra := range strings.Split(s[len(b):], ",", -1) {
+ for _, ra := range strings.Split(s[len(b):], ",") {
i := strings.Index(ra, "-")
if i < 0 {
return nil, os.NewError("invalid range")
diff --git a/src/pkg/http/request.go b/src/pkg/http/request.go
index cd6965f..456476a 100644
--- a/src/pkg/http/request.go
+++ b/src/pkg/http/request.go
@@ -543,7 +543,7 @@
}
var f []string
- if f = strings.Split(s, " ", 3); len(f) < 3 {
+ if f = strings.SplitN(s, " ", 3); len(f) < 3 {
return nil, &badStringError{"malformed HTTP request", s}
}
req.Method, req.RawURL, req.Proto = f[0], f[1], f[2]
@@ -662,11 +662,11 @@
}
func parseQuery(m Values, query string) (err os.Error) {
- for _, kv := range strings.Split(query, "&", -1) {
+ for _, kv := range strings.Split(query, "&") {
if len(kv) == 0 {
continue
}
- kvPair := strings.Split(kv, "=", 2)
+ kvPair := strings.SplitN(kv, "=", 2)
var key, value string
var e os.Error
@@ -703,7 +703,7 @@
return os.NewError("missing form body")
}
ct := r.Header.Get("Content-Type")
- switch strings.Split(ct, ";", 2)[0] {
+ switch strings.SplitN(ct, ";", 2)[0] {
case "text/plain", "application/x-www-form-urlencoded", "":
const maxFormSize = int64(10 << 20) // 10 MB is a lot of text.
b, e := ioutil.ReadAll(io.LimitReader(r.Body, maxFormSize+1))
diff --git a/src/pkg/http/response.go b/src/pkg/http/response.go
index 6c0c441..915327a 100644
--- a/src/pkg/http/response.go
+++ b/src/pkg/http/response.go
@@ -95,7 +95,7 @@
}
return nil, err
}
- f := strings.Split(line, " ", 3)
+ f := strings.SplitN(line, " ", 3)
if len(f) < 2 {
return nil, &badStringError{"malformed HTTP response", line}
}
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go
index 08cbed7..ab960f4 100644
--- a/src/pkg/http/server.go
+++ b/src/pkg/http/server.go
@@ -421,7 +421,7 @@
msg += " would ignore this error page if this text weren't here.\n"
// Is it text? ("Content-Type" is always in the map)
- baseType := strings.Split(w.header.Get("Content-Type"), ";", 2)[0]
+ baseType := strings.SplitN(w.header.Get("Content-Type"), ";", 2)[0]
switch baseType {
case "text/html":
io.WriteString(w, "<!-- ")
diff --git a/src/pkg/http/spdy/read.go b/src/pkg/http/spdy/read.go
index 8adec7b..c6b6ab3 100644
--- a/src/pkg/http/spdy/read.go
+++ b/src/pkg/http/spdy/read.go
@@ -174,7 +174,7 @@
if _, err := io.ReadFull(r, value); err != nil {
return nil, err
}
- valueList := strings.Split(string(value), "\x00", -1)
+ valueList := strings.Split(string(value), "\x00")
for _, v := range valueList {
h.Add(name, v)
}
diff --git a/src/pkg/http/transfer.go b/src/pkg/http/transfer.go
index f72c3d2..2502c1f 100644
--- a/src/pkg/http/transfer.go
+++ b/src/pkg/http/transfer.go
@@ -334,7 +334,7 @@
return nil, nil
}
- encodings := strings.Split(raw[0], ",", -1)
+ encodings := strings.Split(raw[0], ",")
te := make([]string, 0, len(encodings))
// TODO: Even though we only support "identity" and "chunked"
// encodings, the loop below is designed with foresight. One
@@ -450,7 +450,7 @@
header.Del("Trailer")
trailer := make(Header)
- keys := strings.Split(raw, ",", -1)
+ keys := strings.Split(raw, ",")
for _, key := range keys {
key = CanonicalHeaderKey(strings.TrimSpace(key))
switch key {
diff --git a/src/pkg/http/transport.go b/src/pkg/http/transport.go
index 9ad1590..3c16c88 100644
--- a/src/pkg/http/transport.go
+++ b/src/pkg/http/transport.go
@@ -329,7 +329,7 @@
return nil, err
}
if resp.StatusCode != 200 {
- f := strings.Split(resp.Status, " ", 2)
+ f := strings.SplitN(resp.Status, " ", 2)
conn.Close()
return nil, os.NewError(f[1])
}
@@ -383,7 +383,7 @@
addr = addr[:strings.LastIndex(addr, ":")]
}
- for _, p := range strings.Split(no_proxy, ",", -1) {
+ for _, p := range strings.Split(no_proxy, ",") {
p = strings.ToLower(strings.TrimSpace(p))
if len(p) == 0 {
continue
diff --git a/src/pkg/http/url.go b/src/pkg/http/url.go
index beb0b82..e934b27 100644
--- a/src/pkg/http/url.go
+++ b/src/pkg/http/url.go
@@ -508,8 +508,8 @@
// resolvePath applies special path segments from refs and applies
// them to base, per RFC 2396.
func resolvePath(basepath string, refpath string) string {
- base := strings.Split(basepath, "/", -1)
- refs := strings.Split(refpath, "/", -1)
+ base := strings.Split(basepath, "/")
+ refs := strings.Split(refpath, "/")
if len(base) == 0 {
base = []string{""}
}
diff --git a/src/pkg/mail/message.go b/src/pkg/mail/message.go
index fce287b..e227d17 100644
--- a/src/pkg/mail/message.go
+++ b/src/pkg/mail/message.go
@@ -425,7 +425,7 @@
}
func decodeRFC2047Word(s string) (string, os.Error) {
- fields := strings.Split(s, "?", -1)
+ fields := strings.Split(s, "?")
if len(fields) != 5 || fields[0] != "=" || fields[4] != "=" {
return "", os.NewError("mail: address not RFC 2047 encoded")
}
diff --git a/src/pkg/mime/mediatype.go b/src/pkg/mime/mediatype.go
index 96edbd6..40c735c 100644
--- a/src/pkg/mime/mediatype.go
+++ b/src/pkg/mime/mediatype.go
@@ -134,7 +134,7 @@
}
func decode2231Enc(v string) string {
- sv := strings.Split(v, "'", 3)
+ sv := strings.SplitN(v, "'", 3)
if len(sv) != 3 {
return ""
}
diff --git a/src/pkg/patch/patch.go b/src/pkg/patch/patch.go
index d4977dc..fcc8307 100644
--- a/src/pkg/patch/patch.go
+++ b/src/pkg/patch/patch.go
@@ -319,4 +319,4 @@
// splitLines returns the result of splitting s into lines.
// The \n on each line is preserved.
-func splitLines(s []byte) [][]byte { return bytes.SplitAfter(s, newline, -1) }
+func splitLines(s []byte) [][]byte { return bytes.SplitAfter(s, newline) }
diff --git a/src/pkg/path/filepath/path.go b/src/pkg/path/filepath/path.go
index dcd8017..b181483 100644
--- a/src/pkg/path/filepath/path.go
+++ b/src/pkg/path/filepath/path.go
@@ -136,7 +136,7 @@
if path == "" {
return []string{}
}
- return strings.Split(path, string(ListSeparator), -1)
+ return strings.Split(path, string(ListSeparator))
}
// Split splits path immediately following the final Separator,
diff --git a/src/pkg/rpc/server.go b/src/pkg/rpc/server.go
index 17ba6a4..07845d1 100644
--- a/src/pkg/rpc/server.go
+++ b/src/pkg/rpc/server.go
@@ -495,7 +495,7 @@
return
}
- serviceMethod := strings.Split(req.ServiceMethod, ".", -1)
+ serviceMethod := strings.Split(req.ServiceMethod, ".")
if len(serviceMethod) != 2 {
err = os.NewError("rpc: service/method request ill-formed: " + req.ServiceMethod)
return
diff --git a/src/pkg/runtime/debug/stack.go b/src/pkg/runtime/debug/stack.go
index e5fae63..a533a5c 100644
--- a/src/pkg/runtime/debug/stack.go
+++ b/src/pkg/runtime/debug/stack.go
@@ -52,7 +52,7 @@
if err != nil {
continue
}
- lines = bytes.Split(data, []byte{'\n'}, -1)
+ lines = bytes.Split(data, []byte{'\n'})
lastFile = file
}
line-- // in stack trace, lines are 1-indexed but our array is 0-indexed
diff --git a/src/pkg/runtime/debug/stack_test.go b/src/pkg/runtime/debug/stack_test.go
index f4bdc46..4aeea13 100644
--- a/src/pkg/runtime/debug/stack_test.go
+++ b/src/pkg/runtime/debug/stack_test.go
@@ -35,7 +35,7 @@
*/
func TestStack(t *testing.T) {
b := T(0).method()
- lines := strings.Split(string(b), "\n", -1)
+ lines := strings.Split(string(b), "\n")
if len(lines) <= 6 {
t.Fatal("too few lines")
}
diff --git a/src/pkg/smtp/smtp.go b/src/pkg/smtp/smtp.go
index d716df5..2d5e862 100644
--- a/src/pkg/smtp/smtp.go
+++ b/src/pkg/smtp/smtp.go
@@ -93,11 +93,11 @@
return err
}
ext := make(map[string]string)
- extList := strings.Split(msg, "\n", -1)
+ extList := strings.Split(msg, "\n")
if len(extList) > 1 {
extList = extList[1:]
for _, line := range extList {
- args := strings.Split(line, " ", 2)
+ args := strings.SplitN(line, " ", 2)
if len(args) > 1 {
ext[args[0]] = args[1]
} else {
@@ -106,7 +106,7 @@
}
}
if mechs, ok := ext["AUTH"]; ok {
- c.auth = strings.Split(mechs, " ", -1)
+ c.auth = strings.Split(mechs, " ")
}
c.ext = ext
return err
diff --git a/src/pkg/smtp/smtp_test.go b/src/pkg/smtp/smtp_test.go
index 49363ad..c053557 100644
--- a/src/pkg/smtp/smtp_test.go
+++ b/src/pkg/smtp/smtp_test.go
@@ -64,8 +64,8 @@
}
func TestBasic(t *testing.T) {
- basicServer = strings.Join(strings.Split(basicServer, "\n", -1), "\r\n")
- basicClient = strings.Join(strings.Split(basicClient, "\n", -1), "\r\n")
+ basicServer = strings.Join(strings.Split(basicServer, "\n"), "\r\n")
+ basicClient = strings.Join(strings.Split(basicClient, "\n"), "\r\n")
var cmdbuf bytes.Buffer
bcmdbuf := bufio.NewWriter(&cmdbuf)
diff --git a/src/pkg/strconv/fp_test.go b/src/pkg/strconv/fp_test.go
index 34baeee..3096957 100644
--- a/src/pkg/strconv/fp_test.go
+++ b/src/pkg/strconv/fp_test.go
@@ -28,7 +28,7 @@
// Wrapper around strconv.Atof64. Handles dddddp+ddd (binary exponent)
// itself, passes the rest on to strconv.Atof64.
func myatof64(s string) (f float64, ok bool) {
- a := strings.Split(s, "p", 2)
+ a := strings.SplitN(s, "p", 2)
if len(a) == 2 {
n, err := strconv.Atoi64(a[0])
if err != nil {
@@ -72,7 +72,7 @@
// Wrapper around strconv.Atof32. Handles dddddp+ddd (binary exponent)
// itself, passes the rest on to strconv.Atof32.
func myatof32(s string) (f float32, ok bool) {
- a := strings.Split(s, "p", 2)
+ a := strings.SplitN(s, "p", 2)
if len(a) == 2 {
n, err := strconv.Atoi(a[0])
if err != nil {
@@ -116,7 +116,7 @@
if len(line) == 0 || line[0] == '#' {
continue
}
- a := strings.Split(line, " ", -1)
+ a := strings.Split(line, " ")
if len(a) != 4 {
t.Error("testfp.txt:", lineno, ": wrong field count")
continue
diff --git a/src/pkg/strings/strings.go b/src/pkg/strings/strings.go
index bfd0571..6afbc7d 100644
--- a/src/pkg/strings/strings.go
+++ b/src/pkg/strings/strings.go
@@ -198,24 +198,38 @@
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, 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 SplitN(s, sep string, n int) []string { return genSplit(s, sep, 0, n) }
+
+// SplitAfterN slices s into substrings after each instance of sep and
+// returns a slice of those substrings.
+// 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 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.
-// 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) }
+// 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 substrings after each instance of sep and
+// SplitAfter slices s into all substrings after each instance of sep and
// returns a slice of those substrings.
-// If sep is empty, Split 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 {
- return genSplit(s, sep, len(sep), n)
+// 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
diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go
index a1a635d..c546173 100644
--- a/src/pkg/strings/strings_test.go
+++ b/src/pkg/strings/strings_test.go
@@ -186,7 +186,7 @@
func TestExplode(t *testing.T) {
for _, tt := range explodetests {
- a := Split(tt.s, "", tt.n)
+ a := SplitN(tt.s, "", tt.n)
if !eq(a, tt.a) {
t.Errorf("explode(%q, %d) = %v; want %v", tt.s, tt.n, a, tt.a)
continue
@@ -223,7 +223,7 @@
func TestSplit(t *testing.T) {
for _, tt := range splittests {
- a := Split(tt.s, tt.sep, tt.n)
+ a := SplitN(tt.s, tt.sep, tt.n)
if !eq(a, tt.a) {
t.Errorf("Split(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, a, tt.a)
continue
@@ -235,6 +235,12 @@
if s != tt.s {
t.Errorf("Join(Split(%q, %q, %d), %q) = %q", tt.s, tt.sep, tt.n, tt.sep, s)
}
+ if tt.n < 0 {
+ b := Split(tt.s, tt.sep)
+ if !reflect.DeepEqual(a, b) {
+ t.Errorf("Split disagrees with SplitN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
+ }
+ }
}
}
@@ -256,7 +262,7 @@
func TestSplitAfter(t *testing.T) {
for _, tt := range splitaftertests {
- a := SplitAfter(tt.s, tt.sep, tt.n)
+ a := SplitAfterN(tt.s, tt.sep, tt.n)
if !eq(a, tt.a) {
t.Errorf(`Split(%q, %q, %d) = %v; want %v`, tt.s, tt.sep, tt.n, a, tt.a)
continue
@@ -265,6 +271,12 @@
if s != tt.s {
t.Errorf(`Join(Split(%q, %q, %d), %q) = %q`, tt.s, tt.sep, tt.n, tt.sep, s)
}
+ if tt.n < 0 {
+ b := SplitAfter(tt.s, tt.sep)
+ if !reflect.DeepEqual(a, b) {
+ t.Errorf("SplitAfter disagrees with SplitAfterN(%q, %q, %d) = %v; want %v", tt.s, tt.sep, tt.n, b, a)
+ }
+ }
}
}
@@ -623,8 +635,8 @@
if s1 == s2 {
return true
}
- e1 := Split(s1, "", -1)
- e2 := Split(s2, "", -1)
+ e1 := Split(s1, "")
+ e2 := Split(s2, "")
for i, c1 := range e1 {
if i > len(e2) {
break
diff --git a/src/pkg/template/execute.go b/src/pkg/template/execute.go
index 5bc7ff7..464b620 100644
--- a/src/pkg/template/execute.go
+++ b/src/pkg/template/execute.go
@@ -114,7 +114,7 @@
if s == "@" {
return indirectPtr(data, numStars)
}
- for _, elem := range strings.Split(s, ".", -1) {
+ for _, elem := range strings.Split(s, ".") {
// Look up field; data must be a struct or map.
data = t.lookup(st, data, elem)
if !data.IsValid() {
diff --git a/src/pkg/template/parse.go b/src/pkg/template/parse.go
index b4aa5fc..dedf9ad 100644
--- a/src/pkg/template/parse.go
+++ b/src/pkg/template/parse.go
@@ -483,7 +483,7 @@
}
}
words[len(words)-1] = lastWord[0:bar]
- formatters = strings.Split(lastWord[bar+1:], "|", -1)
+ formatters = strings.Split(lastWord[bar+1:], "|")
return
}
diff --git a/src/pkg/testing/testing.go b/src/pkg/testing/testing.go
index 297f6ad..ba72152 100644
--- a/src/pkg/testing/testing.go
+++ b/src/pkg/testing/testing.go
@@ -287,7 +287,7 @@
if len(*cpuListStr) == 0 {
cpuList = append(cpuList, runtime.GOMAXPROCS(-1))
} else {
- for _, val := range strings.Split(*cpuListStr, ",", -1) {
+ for _, val := range strings.Split(*cpuListStr, ",") {
cpu, err := strconv.Atoi(val)
if err != nil || cpu <= 0 {
println("invalid value for -test.cpu")
diff --git a/src/pkg/unicode/maketables.go b/src/pkg/unicode/maketables.go
index 421d294..156e84c 100644
--- a/src/pkg/unicode/maketables.go
+++ b/src/pkg/unicode/maketables.go
@@ -156,7 +156,7 @@
)
func parseCategory(line string) (state State) {
- field := strings.Split(line, ";", -1)
+ field := strings.Split(line, ";")
if len(field) != NumField {
logger.Fatalf("%5s: %d fields (expected %d)\n", line, len(field), NumField)
}
@@ -253,7 +253,7 @@
// Extract the version number from the URL
func version() string {
// Break on slashes and look for the first numeric field
- fields := strings.Split(*url, "/", -1)
+ fields := strings.Split(*url, "/")
for _, f := range fields {
if len(f) > 0 && '0' <= f[0] && f[0] <= '9' {
return f
@@ -336,7 +336,7 @@
if line[0] == '#' {
continue
}
- field := strings.Split(line, "; ", -1)
+ field := strings.Split(line, "; ")
if len(field) != 4 {
logger.Fatalf("CaseFolding.txt %.5s...: %d fields (expected %d)\n", line, len(field), 4)
}
@@ -372,7 +372,7 @@
return
}
// Find out which categories to dump
- list := strings.Split(*tablelist, ",", -1)
+ list := strings.Split(*tablelist, ",")
if *tablelist == "all" {
list = allCategories()
}
@@ -588,7 +588,7 @@
if len(line) == 0 {
return
}
- field := strings.Split(line, ";", -1)
+ field := strings.Split(line, ";")
if len(field) != 2 {
logger.Fatalf("%s: %d fields (expected 2)\n", line, len(field))
}
@@ -685,7 +685,7 @@
resp.Body.Close()
// Find out which scripts to dump
- list := strings.Split(flaglist, ",", -1)
+ list := strings.Split(flaglist, ",")
if flaglist == "all" {
list = all(table)
}