diff --git a/misc/dashboard/builder/main.go b/misc/dashboard/builder/main.go index 9a714fe79fae0dbc0fc5ef6e0fed7d3d05720057..bee663d6cff24a234b494102cc70fb535252c7e3 100644 --- a/misc/dashboard/builder/main.go +++ b/misc/dashboard/builder/main.go @@ -161,7 +161,7 @@ func NewBuilder(builder string) (*Builder, os.Error) { b := &Builder{name: builder} // get goos/goarch from builder string - s := strings.Split(builder, "-", 3) + s := strings.SplitN(builder, "-", 3) if len(s) >= 2 { b.goos, b.goarch = s[0], s[1] } else { @@ -177,7 +177,7 @@ func NewBuilder(builder string) (*Builder, os.Error) { if err != nil { return nil, fmt.Errorf("readKeys %s (%s): %s", b.name, fn, err) } - v := strings.Split(string(c), "\n", -1) + v := strings.Split(string(c), "\n") b.key = v[0] if len(v) >= 3 { b.codeUsername, b.codePassword = v[1], v[2] @@ -392,7 +392,7 @@ func (b *Builder) envvWindows() []string { skip[name] = true } for _, kv := range os.Environ() { - s := strings.Split(kv, "=", 2) + s := strings.SplitN(kv, "=", 2) name := strings.ToUpper(s[0]) switch { case name == "": @@ -602,7 +602,7 @@ var revisionRe = regexp.MustCompile(`^([^ ]+) +[0-9]+:([0-9a-f]+)$`) // firstTag returns the hash and tag of the most recent tag matching re. func firstTag(re *regexp.Regexp) (hash string, tag string, err os.Error) { o, _, err := runLog(nil, "", goroot, "hg", "tags") - for _, l := range strings.Split(o, "\n", -1) { + for _, l := range strings.Split(o, "\n") { if l == "" { continue } diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 6b930f151efbfc729a27c93a5bbf3a348b94521a..a4d83f1e7feb6ad33029f542e39702b1155637e2 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -66,7 +66,7 @@ func cname(s string) string { // preamble. Multiple occurrences are concatenated with a separating space, // even across files. func (p *Package) ParseFlags(f *File, srcfile string) { - linesIn := strings.Split(f.Preamble, "\n", -1) + linesIn := strings.Split(f.Preamble, "\n") linesOut := make([]string, 0, len(linesIn)) NextLine: @@ -78,7 +78,7 @@ NextLine: } l = strings.TrimSpace(l[4:]) - fields := strings.Split(l, ":", 2) + fields := strings.SplitN(l, ":", 2) if len(fields) != 2 { fatalf("%s: bad #cgo line: %s", srcfile, line) } @@ -275,7 +275,7 @@ func (p *Package) loadDefines(f *File) { b.WriteString(f.Preamble) stdout := p.gccDefines(b.Bytes()) - for _, line := range strings.Split(stdout, "\n", -1) { + for _, line := range strings.Split(stdout, "\n") { if len(line) < 9 || line[0:7] != "#define" { continue } @@ -397,7 +397,7 @@ func (p *Package) guessKinds(f *File) []*Name { isConst[i] = true // until proven otherwise } - for _, line := range strings.Split(stderr, "\n", -1) { + for _, line := range strings.Split(stderr, "\n") { if len(line) < 9 || line[0:9] != "cgo-test:" { // the user will see any compiler errors when the code is compiled later. continue @@ -1188,7 +1188,7 @@ func (c *typeConv) Type(dtype dwarf.Type) *Type { if ss, ok := dwarfToName[s]; ok { s = ss } - s = strings.Join(strings.Split(s, " ", -1), "") // strip spaces + s = strings.Join(strings.Split(s, " "), "") // strip spaces name := c.Ident("_Ctype_" + s) typedef[name.Name] = t.Go t.Go = name diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 7eecb3437fc8ed6ad3c32a66944a237f18888d93..6802dd1cf33123ed954aba45f6e747e78203919e 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -148,7 +148,7 @@ func dynimport(obj string) { fatalf("cannot load imported symbols from PE file %s: %v", obj, err) } for _, s := range sym { - ss := strings.Split(s, ":", -1) + ss := strings.Split(s, ":") fmt.Printf("#pragma dynimport %s %s %q\n", ss[0], ss[0], strings.ToLower(ss[1])) } return diff --git a/src/cmd/godoc/dirtrees.go b/src/cmd/godoc/dirtrees.go index af44fa16ad5934a348744926203d5152db381113..ec969b74a4fbe12a25109369db1107ef8f61dd6a 100644 --- a/src/cmd/godoc/dirtrees.go +++ b/src/cmd/godoc/dirtrees.go @@ -267,8 +267,8 @@ func (dir *Directory) lookupLocal(name string) *Directory { // lookup looks for the *Directory for a given path, relative to dir. func (dir *Directory) lookup(path string) *Directory { - d := strings.Split(dir.Path, string(filepath.Separator), -1) - p := strings.Split(path, string(filepath.Separator), -1) + d := strings.Split(dir.Path, string(filepath.Separator)) + p := strings.Split(path, string(filepath.Separator)) i := 0 for i < len(d) { if i >= len(p) || d[i] != p[i] { diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 30f18e882092ce90a7d6f6bde967a4797b69b472..8209781225a99c340319e5df627e3bf75f146062 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -160,7 +160,7 @@ func readDirList(filename string) ([]string, os.Error) { } return e == nil && isPkgDir(d) } - list := canonicalizePaths(strings.Split(string(contents), "\n", -1), filter) + list := canonicalizePaths(strings.Split(string(contents), "\n"), filter) // for each parent path, remove all it's children q // (requirement for binary search to work when filtering) i := 0 diff --git a/src/cmd/godoc/index.go b/src/cmd/godoc/index.go index 61caee101da16ed8f2a89a1357bd8ecfc2844c80..91bd905d8ef0a75613f43c71c7e8acd9d8093aee 100644 --- a/src/cmd/godoc/index.go +++ b/src/cmd/godoc/index.go @@ -901,7 +901,7 @@ func isIdentifier(s string) bool { // identifier, Lookup returns a LookupResult, and a list of alternative // spellings, if any. If the query syntax is wrong, an error is reported. func (x *Index) Lookup(query string) (match *LookupResult, alt *AltWords, err os.Error) { - ss := strings.Split(query, ".", -1) + ss := strings.Split(query, ".") // check query syntax for _, s := range ss { diff --git a/src/cmd/gofix/Makefile b/src/cmd/gofix/Makefile index bce22121e0bd61ccc70a3c1c1be5e7d5a33496ae..02d7463078bb50c4d20c86200c3121447af861d5 100644 --- a/src/cmd/gofix/Makefile +++ b/src/cmd/gofix/Makefile @@ -19,6 +19,7 @@ GOFILES=\ procattr.go\ reflect.go\ sortslice.go\ + stringssplit.go\ typecheck.go\ include ../../Make.cmd diff --git a/src/cmd/gofix/main.go b/src/cmd/gofix/main.go index 05495bc0d822f3f1ee2f9aef66abcfa0bace39eb..e7e7013c568b6eefe5f17ddba806a10529fe394a 100644 --- a/src/cmd/gofix/main.go +++ b/src/cmd/gofix/main.go @@ -53,7 +53,7 @@ func main() { if *allowedRewrites != "" { allowed = make(map[string]bool) - for _, f := range strings.Split(*allowedRewrites, ",", -1) { + for _, f := range strings.Split(*allowedRewrites, ",") { allowed[f] = true } } diff --git a/src/cmd/gofix/stringssplit.go b/src/cmd/gofix/stringssplit.go new file mode 100644 index 0000000000000000000000000000000000000000..4a1fe93d39a2a32fcf52475755e1ba1f68efabba --- /dev/null +++ b/src/cmd/gofix/stringssplit.go @@ -0,0 +1,71 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "go/ast" + "go/token" +) + +var stringssplitFix = fix{ + "stringssplit", + stringssplit, + `Restore strings.Split to its original meaning and add strings.SplitN. Bytes too. + +http://codereview.appspot.com/4661051 +`, +} + +func init() { + register(stringssplitFix) +} + +func stringssplit(f *ast.File) bool { + if !imports(f, "bytes") && !imports(f, "strings") { + return false + } + + fixed := false + walk(f, func(n interface{}) { + call, ok := n.(*ast.CallExpr) + // func Split(s, sep string, n int) []string + // func SplitAfter(s, sep string, n int) []string + if !ok || len(call.Args) != 3 { + return + } + // Is this our function? + switch { + case isPkgDot(call.Fun, "bytes", "Split"): + case isPkgDot(call.Fun, "bytes", "SplitAfter"): + case isPkgDot(call.Fun, "strings", "Split"): + case isPkgDot(call.Fun, "strings", "SplitAfter"): + default: + return + } + + sel := call.Fun.(*ast.SelectorExpr) + args := call.Args + fixed = true // We're committed. + + // Is the last argument -1? If so, drop the arg. + // (Actually we just look for a negative integer literal.) + // Otherwise, Split->SplitN and keep the arg. + final := args[2] + if unary, ok := final.(*ast.UnaryExpr); ok && unary.Op == token.SUB { + if lit, ok := unary.X.(*ast.BasicLit); ok { + // Is it an integer? If so, it's a negative integer and that's what we're after. + if lit.Kind == token.INT { + // drop the last arg. + call.Args = args[0:2] + return + } + } + } + + // If not, rename and keep the argument list. + sel.Sel.Name += "N" + }) + return fixed +} diff --git a/src/cmd/gofix/stringssplit_test.go b/src/cmd/gofix/stringssplit_test.go new file mode 100644 index 0000000000000000000000000000000000000000..b925722af79d689c61616f0d38c8dcabc3c8a0a7 --- /dev/null +++ b/src/cmd/gofix/stringssplit_test.go @@ -0,0 +1,51 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func init() { + addTestCases(stringssplitTests) +} + +var stringssplitTests = []testCase{ + { + Name: "stringssplit.0", + In: `package main + +import ( + "bytes" + "strings" +) + +func f() { + bytes.Split(a, b, c) + bytes.Split(a, b, -1) + bytes.SplitAfter(a, b, c) + bytes.SplitAfter(a, b, -1) + strings.Split(a, b, c) + strings.Split(a, b, -1) + strings.SplitAfter(a, b, c) + strings.SplitAfter(a, b, -1) +} +`, + Out: `package main + +import ( + "bytes" + "strings" +) + +func f() { + bytes.SplitN(a, b, c) + bytes.Split(a, b) + bytes.SplitAfterN(a, b, c) + bytes.SplitAfter(a, b) + strings.SplitN(a, b, c) + strings.Split(a, b) + strings.SplitAfterN(a, b, c) + strings.SplitAfter(a, b) +} +`, + }, +} diff --git a/src/cmd/gofix/testdata/reflect.template.go.in b/src/cmd/gofix/testdata/reflect.template.go.in index ba06de4e3ab024cbff8ddb72d5c8a3230f584426..1f5a8128fdddb4441e0121f285a18da01ae0aee4 100644 --- a/src/cmd/gofix/testdata/reflect.template.go.in +++ b/src/cmd/gofix/testdata/reflect.template.go.in @@ -444,7 +444,7 @@ func (t *Template) newVariable(words []string) *variableElement { bar := strings.IndexRune(lastWord, '|') if bar >= 0 { words[len(words)-1] = lastWord[0:bar] - formatters = strings.Split(lastWord[bar+1:], "|", -1) + formatters = strings.Split(lastWord[bar+1:], "|") } // We could remember the function address here and avoid the lookup later, @@ -705,7 +705,7 @@ func (t *Template) findVar(st *state, s string) reflect.Value { 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 == nil { diff --git a/src/cmd/gofix/testdata/reflect.template.go.out b/src/cmd/gofix/testdata/reflect.template.go.out index c3628845593583339a098a9b6f803e58f4f9cd06..f2f56ef3c291259d9024f4ab0c0768abf24444ce 100644 --- a/src/cmd/gofix/testdata/reflect.template.go.out +++ b/src/cmd/gofix/testdata/reflect.template.go.out @@ -444,7 +444,7 @@ func (t *Template) newVariable(words []string) *variableElement { bar := strings.IndexRune(lastWord, '|') if bar >= 0 { words[len(words)-1] = lastWord[0:bar] - formatters = strings.Split(lastWord[bar+1:], "|", -1) + formatters = strings.Split(lastWord[bar+1:], "|") } // We could remember the function address here and avoid the lookup later, @@ -705,7 +705,7 @@ func (t *Template) findVar(st *state, s string) reflect.Value { 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/cmd/gofmt/gofmt_test.go b/src/cmd/gofmt/gofmt_test.go index a72530307eeac7c257396750107f7c45d0cf3c41..70700554ba7f0870bdf3e786d4b4f374abeb10f2 100644 --- a/src/cmd/gofmt/gofmt_test.go +++ b/src/cmd/gofmt/gofmt_test.go @@ -20,8 +20,8 @@ func runTest(t *testing.T, dirname, in, out, flags string) { // process flags *simplifyAST = false *rewriteRule = "" - for _, flag := range strings.Split(flags, " ", -1) { - elts := strings.Split(flag, "=", 2) + for _, flag := range strings.Split(flags, " ") { + elts := strings.SplitN(flag, "=", 2) name := elts[0] value := "" if len(elts) == 2 { diff --git a/src/cmd/gofmt/rewrite.go b/src/cmd/gofmt/rewrite.go index 4c24282f369e7e5505e63021c30b40bb1a8508e0..f7f1fe824353dd5cd3e953b0ea49cd281deecbe5 100644 --- a/src/cmd/gofmt/rewrite.go +++ b/src/cmd/gofmt/rewrite.go @@ -22,7 +22,7 @@ func initRewrite() { rewrite = nil // disable any previous rewrite return } - f := strings.Split(*rewriteRule, "->", -1) + f := strings.Split(*rewriteRule, "->") if len(f) != 2 { fmt.Fprintf(os.Stderr, "rewrite rule must be of the form 'pattern -> replacement'\n") os.Exit(2) diff --git a/src/cmd/goinstall/download.go b/src/cmd/goinstall/download.go index d209fa82bf37c094d68593111f6fd35bacc68ef0..129c0459a6bae99fc0ca697a9d894809e0d2b53e 100644 --- a/src/cmd/goinstall/download.go +++ b/src/cmd/goinstall/download.go @@ -146,11 +146,11 @@ var vcsList = []*vcs{&git, &hg, &bzr, &svn} // hostname - i.e. contains at least one '.' and the last part is at least 2 // characters. func isRemote(pkg string) bool { - parts := strings.Split(pkg, "/", 2) + parts := strings.SplitN(pkg, "/", 2) if len(parts) != 2 { return false } - parts = strings.Split(parts[0], ".", -1) + parts = strings.Split(parts[0], ".") if len(parts) < 2 || len(parts[len(parts)-1]) < 2 { return false } diff --git a/src/cmd/govet/govet.go b/src/cmd/govet/govet.go index b811c61a2d9e1e934f9cca92f68c54c646e5119c..73bd2faeffaede30668883d0e7d003656149ca3c 100644 --- a/src/cmd/govet/govet.go +++ b/src/cmd/govet/govet.go @@ -50,7 +50,7 @@ func main() { flag.Parse() if *printfuncs != "" { - for _, name := range strings.Split(*printfuncs, ",", -1) { + for _, name := range strings.Split(*printfuncs, ",") { if len(name) == 0 { flag.Usage() } diff --git a/src/cmd/goyacc/goyacc.go b/src/cmd/goyacc/goyacc.go index 220c9949202eb9324a955b456543535773aee504..543f8b1e862cd172b55a01bf53493c0a63d375be 100644 --- a/src/cmd/goyacc/goyacc.go +++ b/src/cmd/goyacc/goyacc.go @@ -2834,7 +2834,7 @@ func others() { // copy yaccpar fmt.Fprintf(ftable, "\n//line yaccpar:1\n") - parts := strings.Split(yaccpar, prefix+"run()", 2) + parts := strings.SplitN(yaccpar, prefix+"run()", 2) fmt.Fprintf(ftable, "%v", parts[0]) ftable.Write(fcode.Bytes()) fmt.Fprintf(ftable, "%v", parts[1]) diff --git a/src/cmd/hgpatch/main.go b/src/cmd/hgpatch/main.go index 1f3e5e73652d07bde648883b4635c6bf2cd50655..6a197bd54b5e08aa75421b7a78189023ed8be26c 100644 --- a/src/cmd/hgpatch/main.go +++ b/src/cmd/hgpatch/main.go @@ -282,7 +282,7 @@ func hgModified() ([]string, os.Error) { if err != nil { return nil, err } - return strings.Split(strings.TrimSpace(out), "\n", -1), nil + return strings.Split(strings.TrimSpace(out), "\n"), nil } // hgAdd adds name to the repository. diff --git a/src/pkg/asn1/common.go b/src/pkg/asn1/common.go index 9db887e251ba66b65c072b1a8d70fe3a5cfd15be..854f4da4808cde0f7ac368aaa42625653dc92465 100644 --- a/src/pkg/asn1/common.go +++ b/src/pkg/asn1/common.go @@ -83,7 +83,7 @@ type fieldParameters struct { // 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 0f9ac98637144427658f07035fb6a32381bdd753..3cec60f96c9a632774c90ccb92b3af39b58bd1ba 100644 --- a/src/pkg/bytes/bytes.go +++ b/src/pkg/bytes/bytes.go @@ -212,26 +212,40 @@ func genSplit(s, sep []byte, sepSave, n int) [][]byte { 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, Split splits after each UTF-8 sequence. +// 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 Split(s, sep []byte, n int) [][]byte { return genSplit(s, sep, 0, n) } +func SplitN(s, sep []byte, n int) [][]byte { return genSplit(s, sep, 0, n) } -// SplitAfter slices s into subslices after each instance of sep and +// SplitAfterN slices s into subslices after each instance of sep and // returns a slice of those subslices. -// If sep is empty, Split splits after each UTF-8 sequence. +// 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 SplitAfter(s, sep []byte, n int) [][]byte { +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. +// 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 all subslices after each instance of sep and +// returns a slice of those subslices. +// 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 // characters, returning a slice of subarrays of s or an empty list if s contains only white space. func Fields(s []byte) [][]byte { diff --git a/src/pkg/bytes/bytes_test.go b/src/pkg/bytes/bytes_test.go index 4ce291a4f67b2fc05935f1df6405fa406e75d563..7539353091821c3e410263af90563391bbb7003d 100644 --- a/src/pkg/bytes/bytes_test.go +++ b/src/pkg/bytes/bytes_test.go @@ -6,6 +6,7 @@ package bytes_test import ( . "bytes" + "reflect" "testing" "unicode" "utf8" @@ -315,7 +316,7 @@ var explodetests = []ExplodeTest{ 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 @@ var splittests = []SplitTest{ 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 @@ func TestSplit(t *testing.T) { 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 @@ var splitaftertests = []SplitTest{ 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 @@ func TestSplitAfter(t *testing.T) { 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 72121a6b5696261fbd988c583fb316f9fb3fcf13..f8042b0d191334f665d291853711826065f6ec0f 100644 --- a/src/pkg/compress/lzw/reader_test.go +++ b/src/pkg/compress/lzw/reader_test.go @@ -84,7 +84,7 @@ var lzwTests = []lzwTest{ 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 9145880a2370f8d3f9f34deed2262c9e39ae9610..20a81574d0a82694f1730ebc597318bca72387bb 100644 --- a/src/pkg/crypto/x509/verify.go +++ b/src/pkg/crypto/x509/verify.go @@ -202,8 +202,8 @@ func matchHostnames(pattern, host string) bool { 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 5831b0e9795f814c6f7f2d180501f8bd09b2d143..7ec797114c455e63de814b6e9f067451877954c5 100644 --- a/src/pkg/debug/proc/proc_linux.go +++ b/src/pkg/debug/proc/proc_linux.go @@ -1229,7 +1229,7 @@ func (p *process) attachAllThreads() os.Error { 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 c45a7d70a65d7c54c9a6b2a6e5206d5e735c4432..f6cebb9055373f602f1835d638a7192dd936e679 100644 --- a/src/pkg/exec/exec_test.go +++ b/src/pkg/exec/exec_test.go @@ -55,7 +55,7 @@ func TestCatGoodAndBadFile(t *testing.T) { 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 c4e2a7a0f93280aec2ad46ec2609a6201b385af9..e4751a4df29c6209ad641043ccc2b626b7c7faf9 100644 --- a/src/pkg/exec/lp_plan9.go +++ b/src/pkg/exec/lp_plan9.go @@ -42,7 +42,7 @@ func LookPath(file string) (string, os.Error) { } 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 cdf7207688cb1059e6e726c6c896e6e1ad3442de..008fb11a81c01186193a1fab5119cd72eee28391 100644 --- a/src/pkg/exec/lp_unix.go +++ b/src/pkg/exec/lp_unix.go @@ -39,7 +39,7 @@ func LookPath(file string) (string, os.Error) { 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 47763458f81607cbd71826b5f9d03fa625ff68ab..7581088eb09a1126f22bd5bd50b2ea81fdc22b33 100644 --- a/src/pkg/exec/lp_windows.go +++ b/src/pkg/exec/lp_windows.go @@ -47,7 +47,7 @@ func LookPath(file string) (f string, err os.Error) { 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 @@ func LookPath(file string) (f string, err os.Error) { 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 a8db523ea18e9cdb17f5559b19e5f8366511e819..ff0d24c692f2f6759598ed26aedc78e7db38e4aa 100644 --- a/src/pkg/exp/ogle/cmd.go +++ b/src/pkg/exp/ogle/cmd.go @@ -154,7 +154,7 @@ func cmdLoad(args []byte) os.Error { } 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 0820dcfcef25179ec0a29c9e89a77964d9f927b5..30b396fcf650a51e57595444abedb5538d4698fc 100644 --- a/src/pkg/go/ast/print_test.go +++ b/src/pkg/go/ast/print_test.go @@ -53,7 +53,7 @@ var tests = []struct { // 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 20f8f2913f86ea5b07398c36f337f81569ffc5fd..e0000b534468edfbb1e3358a625ca439edd9295c 100644 --- a/src/pkg/go/build/dir.go +++ b/src/pkg/go/build/dir.go @@ -139,7 +139,7 @@ func goodOSArch(filename string) bool { 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 f1ebfa97b9f7dc7d4794fafaa7c5b923b875ec6c..85640af796e787d52d58409a021f66aab03f3652 100644 --- a/src/pkg/go/doc/comment.go +++ b/src/pkg/go/doc/comment.go @@ -58,7 +58,7 @@ func CommentText(comment *ast.CommentGroup) string { } // 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 c17b436aab4070f6fbb79b38b3868bf13ff68516..c794612abcfabd3f87b562ea855fcb16bbebacf0 100644 --- a/src/pkg/html/token_test.go +++ b/src/pkg/html/token_test.go @@ -161,7 +161,7 @@ func TestTokenizer(t *testing.T) { 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 2be3ede774a8deced42a8867053e9e17a86b6184..01a941650bd34886127170adeb833a809f7b19f4 100644 --- a/src/pkg/http/cgi/host.go +++ b/src/pkg/http/cgi/host.go @@ -197,7 +197,7 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { 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 bbdb715cf91ae1527fbcb698a96914b9c385ab12..3b9dad5c0c584f8471264338f2986f39af8d5628 100644 --- a/src/pkg/http/cgi/host_test.go +++ b/src/pkg/http/cgi/host_test.go @@ -46,7 +46,7 @@ readlines: } 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 79c239b46e74471e46b3ea5e3eb0c351bfa53e9a..fe70431bbbcc046c04ab014e81d61890e71f55c0 100644 --- a/src/pkg/http/cookie.go +++ b/src/pkg/http/cookie.go @@ -41,7 +41,7 @@ type Cookie struct { 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 @@ func readCookies(h Header, filter string) []*Cookie { } 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 139fe2cb0f4df249e42e0fed5e7558fb951a6e44..0b830053a9b2c2235a39b03e3092faf0cb1d6786 100644 --- a/src/pkg/http/fs.go +++ b/src/pkg/http/fs.go @@ -259,7 +259,7 @@ func parseRange(s string, size int64) ([]httpRange, os.Error) { 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 cd6965fa5db341ef0cf36e5d16d584d5c00de652..456476a2129c6589ca46c8f944efcc03fe0d07a5 100644 --- a/src/pkg/http/request.go +++ b/src/pkg/http/request.go @@ -543,7 +543,7 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) { } 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(query string) (m Values, err os.Error) { } 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 @@ func (r *Request) ParseForm() (err os.Error) { 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 6c0c441a9446be09a71ca4643c5555792f6ff977..915327a69ec5698752c25aa831e79521375110ab 100644 --- a/src/pkg/http/response.go +++ b/src/pkg/http/response.go @@ -95,7 +95,7 @@ func ReadResponse(r *bufio.Reader, req *Request) (resp *Response, err os.Error) } 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 08cbed7ad87b02ad6a860cac25b283af841fb615..ab960f4f0a8e12a08301a1481ef85e50ed8143a4 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -421,7 +421,7 @@ func errorKludge(w *response) { 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 8adec7bd4ffe1c6493798a44bb68bdc09097e3e3..c6b6ab3af849ca90f2a9d243f0c8a535eb0fd65e 100644 --- a/src/pkg/http/spdy/read.go +++ b/src/pkg/http/spdy/read.go @@ -174,7 +174,7 @@ func parseHeaderValueBlock(r io.Reader, streamId uint32) (http.Header, os.Error) 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 f72c3d239a534e8fb53d6d0e77829bafaa4ee6ad..2502c1fee11f479d48fe64900700c19d0388cacc 100644 --- a/src/pkg/http/transfer.go +++ b/src/pkg/http/transfer.go @@ -334,7 +334,7 @@ func fixTransferEncoding(requestMethod string, header Header) ([]string, os.Erro 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 @@ func fixTrailer(header Header, te []string) (Header, os.Error) { 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 9ad159010be43355bd7857f06f4dc3dfee59f3ba..3c16c880d5a1e1a1452c5ad3ce76f9441d5971b6 100644 --- a/src/pkg/http/transport.go +++ b/src/pkg/http/transport.go @@ -329,7 +329,7 @@ func (t *Transport) getConn(cm *connectMethod) (*persistConn, os.Error) { 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 @@ func useProxy(addr string) bool { 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 beb0b8200d022a8e1d95685b58ee6a46aa21c70a..e934b27c4df5c3c40e65def39c9b23e6b5c88630 100644 --- a/src/pkg/http/url.go +++ b/src/pkg/http/url.go @@ -508,8 +508,8 @@ func (v Values) Encode() string { // 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 fce287bd8e6815db4bda635923ee6ca246551f9b..e227d17d6fa38f3123a7173459f966820accebb5 100644 --- a/src/pkg/mail/message.go +++ b/src/pkg/mail/message.go @@ -425,7 +425,7 @@ func (p *addrParser) len() int { } 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 96edbd672590e2e9d12e9e2f924384bccbf6986c..40c735c5baa83a47c56d247edad660ecb4e61f45 100644 --- a/src/pkg/mime/mediatype.go +++ b/src/pkg/mime/mediatype.go @@ -134,7 +134,7 @@ func ParseMediaType(v string) (mediatype string, params map[string]string) { } 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 d4977dc990203137aeb2afee21b514ec1d8ff458..fcc8307e09c1510d1d866ce923442c157f4c5d61 100644 --- a/src/pkg/patch/patch.go +++ b/src/pkg/patch/patch.go @@ -319,4 +319,4 @@ func hasPrefix(s []byte, t string) bool { // 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 dcd8017add1bdaf42cc4b0239bff399634e7a0da..b181483ed6e646f7519b08c057d756f6bc9f2c3d 100644 --- a/src/pkg/path/filepath/path.go +++ b/src/pkg/path/filepath/path.go @@ -136,7 +136,7 @@ func SplitList(path string) []string { 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 17ba6a453aa17126531010801b30a730ab9258a9..07845d128b97801aac14a8768461e62678ee0780 100644 --- a/src/pkg/rpc/server.go +++ b/src/pkg/rpc/server.go @@ -495,7 +495,7 @@ func (server *Server) readRequest(codec ServerCodec) (req *Request, service *ser 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 e5fae632b13cde25f14fba25459d4511fd58553d..a533a5c3bf48cf42632c9721d42b940c8e27d83a 100644 --- a/src/pkg/runtime/debug/stack.go +++ b/src/pkg/runtime/debug/stack.go @@ -52,7 +52,7 @@ func stack() []byte { 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 f4bdc46244fa1e291c0a58b8acd5b86f1a4a167f..4aeea13ffd3cb571e36949e4fb5c89c18196f1ec 100644 --- a/src/pkg/runtime/debug/stack_test.go +++ b/src/pkg/runtime/debug/stack_test.go @@ -35,7 +35,7 @@ func (t T) method() []byte { */ 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 d716df56b9be657f166467d614626b9c40daf122..2d5e862471300dd95609c7d65556efab1b4399a6 100644 --- a/src/pkg/smtp/smtp.go +++ b/src/pkg/smtp/smtp.go @@ -93,11 +93,11 @@ func (c *Client) ehlo() os.Error { 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 @@ func (c *Client) ehlo() os.Error { } } 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 49363adf0a9c5f7bd3bac3a133e5636c167c215c..c053557d7f417c1af8c56cc935906044eee0ad2a 100644 --- a/src/pkg/smtp/smtp_test.go +++ b/src/pkg/smtp/smtp_test.go @@ -64,8 +64,8 @@ func (f faker) Close() os.Error { } 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 34baeee39b3360a7dcc35d41e3a42c038a74e6d3..3096957f5d3ac4b76fab1419d72cf91a6bc348fd 100644 --- a/src/pkg/strconv/fp_test.go +++ b/src/pkg/strconv/fp_test.go @@ -28,7 +28,7 @@ func pow2(i int) float64 { // 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 @@ func myatof64(s string) (f float64, ok bool) { // 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 @@ func TestFp(t *testing.T) { 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 bfd057180d7034ff673fbb1cd310272316b753c1..6afbc7dc2fedc79c21f25c8ebe683d1b4b8632bf 100644 --- a/src/pkg/strings/strings.go +++ b/src/pkg/strings/strings.go @@ -198,26 +198,40 @@ func genSplit(s, sep string, sepSave, n int) []string { 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, Split splits after each UTF-8 sequence. +// 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 Split(s, sep string, n int) []string { return genSplit(s, sep, 0, n) } +func SplitN(s, sep string, n int) []string { return genSplit(s, sep, 0, n) } -// SplitAfter slices s into substrings after each instance of sep and +// SplitAfterN slices s into substrings after each instance of sep and // returns a slice of those substrings. -// If sep is empty, Split splits after each UTF-8 sequence. +// 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 SplitAfter(s, sep string, n int) []string { +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. +// 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 all substrings after each instance of sep and +// returns a slice of those substrings. +// 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 // characters, returning an array of substrings of s or an empty list if s contains only white space. func Fields(s string) []string { diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go index a1a635dddbc6d69a2a90731561851a4e03776305..c546173393d69eac4661559bec3c0304b654fe85 100644 --- a/src/pkg/strings/strings_test.go +++ b/src/pkg/strings/strings_test.go @@ -186,7 +186,7 @@ var explodetests = []ExplodeTest{ 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 @@ var splittests = []SplitTest{ 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 @@ func TestSplit(t *testing.T) { 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 @@ var splitaftertests = []SplitTest{ 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 @@ func TestSplitAfter(t *testing.T) { 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 @@ func equal(m string, s1, s2 string, t *testing.T) bool { 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 5bc7ff7e9faf5150f9fc38c44289a7feff1a8a31..464b620c98b9275faa5db64c6785121facd0e3c3 100644 --- a/src/pkg/template/execute.go +++ b/src/pkg/template/execute.go @@ -114,7 +114,7 @@ func (t *Template) findVar(st *state, s string) reflect.Value { 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 b4aa5fcd2d35fae230276c75d64911bb0c9a3ae3..dedf9ad8e9fa2c50592807153bfc6fab06b160eb 100644 --- a/src/pkg/template/parse.go +++ b/src/pkg/template/parse.go @@ -483,7 +483,7 @@ func extractFormatters(words []string) (formatters []string) { } } 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 297f6ad0dc0d33168f94026824621a2907346f07..ba721523e1bd99725a5ad082f4d6099278c976de 100644 --- a/src/pkg/testing/testing.go +++ b/src/pkg/testing/testing.go @@ -287,7 +287,7 @@ func parseCpuList() { 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 421d29455240c5f348580c878a80532004769f44..156e84c0f023d9a8b9782a9fba7e70b65c44a483 100644 --- a/src/pkg/unicode/maketables.go +++ b/src/pkg/unicode/maketables.go @@ -156,7 +156,7 @@ const ( ) 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 @@ func all(scripts map[string][]Script) []string { // 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 @@ func loadCasefold() { 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 @@ func printCategories() { 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 @@ func parseScript(line string, scripts map[string][]Script) { 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 @@ func printScriptOrProperty(doProps bool) { resp.Body.Close() // Find out which scripts to dump - list := strings.Split(flaglist, ",", -1) + list := strings.Split(flaglist, ",") if flaglist == "all" { list = all(table) }