diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-03-04 21:27:36 +0100 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2013-03-04 21:27:36 +0100 |
commit | 04b08da9af0c450d645ab7389d1467308cfc2db8 (patch) | |
tree | db247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/cmd/fix/stringssplit.go | |
parent | 917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff) | |
download | golang-04b08da9af0c450d645ab7389d1467308cfc2db8.tar.gz |
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/cmd/fix/stringssplit.go')
-rw-r--r-- | src/cmd/fix/stringssplit.go | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/cmd/fix/stringssplit.go b/src/cmd/fix/stringssplit.go deleted file mode 100644 index d89ecf039..000000000 --- a/src/cmd/fix/stringssplit.go +++ /dev/null @@ -1,72 +0,0 @@ -// 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" -) - -func init() { - register(stringssplitFix) -} - -var stringssplitFix = fix{ - "stringssplit", - "2011-06-28", - stringssplit, - `Restore strings.Split to its original meaning and add strings.SplitN. Bytes too. - -http://codereview.appspot.com/4661051 -`, -} - -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 -} |