From 90d71fe99e21b68e292327c966946f1706d66514 Mon Sep 17 00:00:00 2001 From: Marvin Stenger Date: Thu, 5 Oct 2017 15:49:32 +0200 Subject: [PATCH] all: revert "all: prefer strings.IndexByte over strings.Index" This reverts https://golang.org/cl/65930. Fixes #22148 Change-Id: Ie0712621ed89c43bef94417fc32de9af77607760 Reviewed-on: https://go-review.googlesource.com/68430 Reviewed-by: Ian Lance Taylor --- src/cmd/api/goapi.go | 2 +- src/cmd/cgo/gcc.go | 8 ++++---- src/cmd/cgo/godefs.go | 2 +- src/cmd/compile/fmt_test.go | 2 +- src/cmd/compile/internal/gc/main.go | 8 ++++---- src/cmd/compile/internal/gc/noder.go | 2 +- src/cmd/compile/internal/gc/plive.go | 2 +- src/cmd/compile/internal/ssa/gen/rulegen.go | 8 ++++---- src/cmd/compile/internal/syntax/nodes_test.go | 2 +- src/cmd/dist/main.go | 2 +- src/cmd/doc/main.go | 2 +- src/cmd/fix/fix.go | 2 +- src/cmd/fix/typecheck.go | 6 +++--- src/cmd/go/go_test.go | 2 +- src/cmd/go/internal/base/base.go | 2 +- src/cmd/go/internal/cmdflag/flag.go | 2 +- src/cmd/go/internal/get/get.go | 2 +- src/cmd/go/internal/get/vcs.go | 2 +- src/cmd/go/internal/load/match_test.go | 2 +- src/cmd/go/internal/load/pkg.go | 2 +- src/cmd/link/internal/ld/data.go | 2 +- src/cmd/link/internal/ld/deadcode.go | 2 +- src/cmd/link/internal/ld/go.go | 2 +- src/cmd/link/internal/ld/ld.go | 4 ++-- src/cmd/vet/asmdecl.go | 2 +- src/cmd/vet/print.go | 2 +- src/cmd/vet/structtag.go | 2 +- src/crypto/x509/pem_decrypt.go | 2 +- src/crypto/x509/root_darwin_arm_gen.go | 2 +- src/debug/gosym/symtab.go | 4 ++-- src/encoding/json/tags.go | 4 ++-- src/encoding/xml/typeinfo.go | 2 +- src/encoding/xml/xml.go | 2 +- src/go/build/build.go | 8 ++++---- src/go/printer/printer.go | 2 +- src/html/template/js.go | 2 +- src/math/big/ratconv.go | 2 +- src/mime/encodedword.go | 2 +- src/mime/mediatype.go | 6 +++--- src/net/http/cgi/child.go | 2 +- src/net/http/cookie.go | 6 +++--- src/net/http/fs.go | 2 +- src/net/http/request.go | 6 +++--- src/net/http/server.go | 2 +- src/net/lookup_test.go | 2 +- src/net/url/url.go | 6 +++--- src/os/env_test.go | 2 +- src/os/exec/exec.go | 2 +- src/os/os_test.go | 2 +- src/os/user/cgo_lookup_unix.go | 2 +- src/os/user/lookup_unix.go | 2 +- src/regexp/exec_test.go | 4 ++-- src/regexp/regexp.go | 2 +- src/runtime/pprof/pprof_test.go | 2 +- src/unicode/maketables.go | 2 +- 55 files changed, 81 insertions(+), 81 deletions(-) diff --git a/src/cmd/api/goapi.go b/src/cmd/api/goapi.go index a47909b2704..8cc78c01ed4 100644 --- a/src/cmd/api/goapi.go +++ b/src/cmd/api/goapi.go @@ -189,7 +189,7 @@ func main() { features = append(features, f) continue } - comma := strings.IndexByte(f, ',') + comma := strings.Index(f, ",") for cname := range cmap { f2 := fmt.Sprintf("%s (%s)%s", f[:comma], cname, f[comma:]) features = append(features, f2) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index dc80159ef38..99e98cee755 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -204,7 +204,7 @@ func (p *Package) loadDefines(f *File) { line = strings.TrimSpace(line[8:]) var key, val string - spaceIndex := strings.IndexByte(line, ' ') + spaceIndex := strings.Index(line, " ") tabIndex := strings.Index(line, "\t") if spaceIndex == -1 && tabIndex == -1 { @@ -364,11 +364,11 @@ func (p *Package) guessKinds(f *File) []*Name { continue } - c1 := strings.IndexByte(line, ':') + c1 := strings.Index(line, ":") if c1 < 0 { continue } - c2 := strings.IndexByte(line[c1+1:], ':') + c2 := strings.Index(line[c1+1:], ":") if c2 < 0 { continue } @@ -2538,7 +2538,7 @@ func fieldPrefix(fld []*ast.Field) string { if strings.HasPrefix(n.Name, "orig_") || strings.HasPrefix(n.Name, "_") { continue } - i := strings.IndexByte(n.Name, '_') + i := strings.Index(n.Name, "_") if i < 0 { continue } diff --git a/src/cmd/cgo/godefs.go b/src/cmd/cgo/godefs.go index 55736363fbd..6d638f06442 100644 --- a/src/cmd/cgo/godefs.go +++ b/src/cmd/cgo/godefs.go @@ -41,7 +41,7 @@ func (p *Package) godefs(f *File, srcfile string) string { continue } s := strings.TrimSpace(c.Text[i+len("+godefs map"):]) - i = strings.IndexByte(s, ' ') + i = strings.Index(s, " ") if i < 0 { fmt.Fprintf(os.Stderr, "invalid +godefs map comment: %s\n", c.Text) continue diff --git a/src/cmd/compile/fmt_test.go b/src/cmd/compile/fmt_test.go index 96d1fb12f04..6d18d495c37 100644 --- a/src/cmd/compile/fmt_test.go +++ b/src/cmd/compile/fmt_test.go @@ -540,7 +540,7 @@ func init() { for key, val := range knownFormats { // key must be "typename format", and format starts with a '%' // (formats containing '*' alone are not collected in this table) - i := strings.IndexByte(key, '%') + i := strings.Index(key, "%") if i < 0 || !oneFormat(key[i:]) { log.Fatalf("incorrect knownFormats key: %q", key) } diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 5760fa77961..6b23d7b076b 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -364,7 +364,7 @@ func Main(archInit func(*Arch)) { // _ in phase name also matches space phase := name[4:] flag := "debug" // default flag is debug - if i := strings.IndexByte(phase, '/'); i >= 0 { + if i := strings.Index(phase, "/"); i >= 0 { flag = phase[i+1:] phase = phase[:i] } @@ -689,7 +689,7 @@ func addImportMap(s string) { if strings.Count(s, "=") != 1 { log.Fatal("-importmap argument must be of the form source=actual") } - i := strings.IndexByte(s, '=') + i := strings.Index(s, "=") source, actual := s[:i], s[i+1:] if source == "" || actual == "" { log.Fatal("-importmap argument must be of the form source=actual; source and actual must be non-empty") @@ -712,13 +712,13 @@ func readImportCfg(file string) { } var verb, args string - if i := strings.IndexByte(line, ' '); i < 0 { + if i := strings.Index(line, " "); i < 0 { verb = line } else { verb, args = line[:i], strings.TrimSpace(line[i+1:]) } var before, after string - if i := strings.IndexByte(args, '='); i >= 0 { + if i := strings.Index(args, "="); i >= 0 { before, after = args[:i], args[i+1:] } switch verb { diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go index 0e14de90662..fc49c552755 100644 --- a/src/cmd/compile/internal/gc/noder.go +++ b/src/cmd/compile/internal/gc/noder.go @@ -1273,7 +1273,7 @@ func (p *noder) pragma(pos src.Pos, text string) syntax.Pragma { fallthrough // because of //go:cgo_unsafe_args default: verb := text - if i := strings.IndexByte(text, ' '); i >= 0 { + if i := strings.Index(text, " "); i >= 0 { verb = verb[:i] } prag := pragmaValue(verb) diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go index 7f779c2df1d..9d2dcf658f9 100644 --- a/src/cmd/compile/internal/gc/plive.go +++ b/src/cmd/compile/internal/gc/plive.go @@ -1045,7 +1045,7 @@ func (lv *Liveness) showlive(v *ssa.Value, live bvec) { s += fmt.Sprintf("entry to %s:", lv.fn.funcname()) } else if sym, ok := v.Aux.(*obj.LSym); ok { fn := sym.Name - if pos := strings.IndexByte(fn, '.'); pos >= 0 { + if pos := strings.Index(fn, "."); pos >= 0 { fn = fn[pos+1:] } s += fmt.Sprintf("call to %s:", fn) diff --git a/src/cmd/compile/internal/ssa/gen/rulegen.go b/src/cmd/compile/internal/ssa/gen/rulegen.go index d35c80cd8a0..c23a54d9b5d 100644 --- a/src/cmd/compile/internal/ssa/gen/rulegen.go +++ b/src/cmd/compile/internal/ssa/gen/rulegen.go @@ -475,8 +475,8 @@ func genMatch0(w io.Writer, arch arch, match, v string, m map[string]struct{}, t } // compound sexpr var argname string - colon := strings.IndexByte(arg, ':') - openparen := strings.IndexByte(arg, '(') + colon := strings.Index(arg, ":") + openparen := strings.Index(arg, "(") if colon >= 0 && openparen >= 0 && colon < openparen { // rule-specified name argname = arg[:colon] @@ -817,7 +817,7 @@ func commute1(m string, cnt map[string]int, arch arch) []string { } // Split up input. var prefix string - colon := strings.IndexByte(m, ':') + colon := strings.Index(m, ":") if colon >= 0 && isVariable(m[:colon]) { prefix = m[:colon+1] m = m[colon+1:] @@ -912,7 +912,7 @@ func varCount1(m string, cnt map[string]int) { return } // Split up input. - colon := strings.IndexByte(m, ':') + colon := strings.Index(m, ":") if colon >= 0 && isVariable(m[:colon]) { cnt[m[:colon]]++ m = m[colon+1:] diff --git a/src/cmd/compile/internal/syntax/nodes_test.go b/src/cmd/compile/internal/syntax/nodes_test.go index 9d7beb997f5..1bba9eeacff 100644 --- a/src/cmd/compile/internal/syntax/nodes_test.go +++ b/src/cmd/compile/internal/syntax/nodes_test.go @@ -313,7 +313,7 @@ func testPos(t *testing.T, list []test, prefix, suffix string, extract func(*Fil } func stripAt(s string) (string, int) { - if i := strings.IndexByte(s, '@'); i >= 0 { + if i := strings.Index(s, "@"); i >= 0 { return s[:i] + s[i+1:], i } return s, -1 diff --git a/src/cmd/dist/main.go b/src/cmd/dist/main.go index 6e63eddfe52..a72a2607f9f 100644 --- a/src/cmd/dist/main.go +++ b/src/cmd/dist/main.go @@ -137,7 +137,7 @@ func main() { // so OS X 10.6 is uname version 10 and OS X 10.8 is uname version 12. if gohostos == "darwin" { rel := run("", CheckExit, "uname", "-r") - if i := strings.IndexByte(rel, '.'); i >= 0 { + if i := strings.Index(rel, "."); i >= 0 { rel = rel[:i] } osx, _ := strconv.Atoi(rel) diff --git a/src/cmd/doc/main.go b/src/cmd/doc/main.go index 78ea038e61e..e0a71121933 100644 --- a/src/cmd/doc/main.go +++ b/src/cmd/doc/main.go @@ -215,7 +215,7 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo // slash+1: if there's no slash, the value is -1 and start is 0; otherwise // start is the byte after the slash. for start := slash + 1; start < len(arg); start = period + 1 { - period = strings.IndexByte(arg[start:], '.') + period = strings.Index(arg[start:], ".") symbol := "" if period < 0 { period = len(arg) diff --git a/src/cmd/fix/fix.go b/src/cmd/fix/fix.go index f12d1c7fe0e..ebed82fbeb6 100644 --- a/src/cmd/fix/fix.go +++ b/src/cmd/fix/fix.go @@ -791,7 +791,7 @@ func renameFix(tab []rename) func(*ast.File) bool { } func parseName(s string) (ptr bool, pkg, nam string) { - i := strings.IndexByte(s, '.') + i := strings.Index(s, ".") if i < 0 { panic("parseName: invalid name " + s) } diff --git a/src/cmd/fix/typecheck.go b/src/cmd/fix/typecheck.go index e2b89edc7da..0352c49db0f 100644 --- a/src/cmd/fix/typecheck.go +++ b/src/cmd/fix/typecheck.go @@ -471,7 +471,7 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a if strings.HasPrefix(t, "[") || strings.HasPrefix(t, "map[") { // Lazy: assume there are no nested [] in the array // length or map key type. - if i := strings.IndexByte(t, ']'); i >= 0 { + if i := strings.Index(t, "]"); i >= 0 { typeof[n] = t[i+1:] } } @@ -512,11 +512,11 @@ func typecheck1(cfg *TypeConfig, f interface{}, typeof map[interface{}]string, a key, value = "int", "rune" } else if strings.HasPrefix(t, "[") { key = "int" - if i := strings.IndexByte(t, ']'); i >= 0 { + if i := strings.Index(t, "]"); i >= 0 { value = t[i+1:] } } else if strings.HasPrefix(t, "map[") { - if i := strings.IndexByte(t, ']'); i >= 0 { + if i := strings.Index(t, "]"); i >= 0 { key, value = t[4:i], t[i+1:] } } diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 625b4eea9a0..537d5969914 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -223,7 +223,7 @@ func (tg *testgoData) parallel() { } for _, e := range tg.env { if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") { - val := e[strings.IndexByte(e, '=')+1:] + val := e[strings.Index(e, "=")+1:] if strings.HasPrefix(val, "testdata") || strings.HasPrefix(val, "./testdata") { tg.t.Fatalf("internal testsuite error: call to parallel with testdata in environment (%s)", e) } diff --git a/src/cmd/go/internal/base/base.go b/src/cmd/go/internal/base/base.go index 1026ed0fa53..aff33f70d8d 100644 --- a/src/cmd/go/internal/base/base.go +++ b/src/cmd/go/internal/base/base.go @@ -54,7 +54,7 @@ var Commands []*Command // Name returns the command's name: the first word in the usage line. func (c *Command) Name() string { name := c.UsageLine - i := strings.IndexByte(name, ' ') + i := strings.Index(name, " ") if i >= 0 { name = name[:i] } diff --git a/src/cmd/go/internal/cmdflag/flag.go b/src/cmd/go/internal/cmdflag/flag.go index b14bda89638..7ab30221279 100644 --- a/src/cmd/go/internal/cmdflag/flag.go +++ b/src/cmd/go/internal/cmdflag/flag.go @@ -87,7 +87,7 @@ func Parse(cmd string, defns []*Defn, args []string, i int) (f *Defn, value stri name := arg[1:] // If there's already a prefix such as "test.", drop it for now. name = strings.TrimPrefix(name, cmd+".") - equals := strings.IndexByte(name, '=') + equals := strings.Index(name, "=") if equals >= 0 { value = name[equals+1:] name = name[:equals] diff --git a/src/cmd/go/internal/get/get.go b/src/cmd/go/internal/get/get.go index d62adffb46d..bef1d761c89 100644 --- a/src/cmd/go/internal/get/get.go +++ b/src/cmd/go/internal/get/get.go @@ -501,7 +501,7 @@ func downloadPackage(p *load.Package) error { return err } vers := runtime.Version() - if i := strings.IndexByte(vers, ' '); i >= 0 { + if i := strings.Index(vers, " "); i >= 0 { vers = vers[:i] } if err := vcs.tagSync(root, selectTag(vers, tags)); err != nil { diff --git a/src/cmd/go/internal/get/vcs.go b/src/cmd/go/internal/get/vcs.go index 6b32bb31778..5c2513b261c 100644 --- a/src/cmd/go/internal/get/vcs.go +++ b/src/cmd/go/internal/get/vcs.go @@ -755,7 +755,7 @@ func repoRootFromVCSPaths(importPath, scheme string, security web.SecurityMode, // // This handles custom import paths like "name.tld/pkg/foo" or just "name.tld". func repoRootForImportDynamic(importPath string, security web.SecurityMode) (*repoRoot, error) { - slash := strings.IndexByte(importPath, '/') + slash := strings.Index(importPath, "/") if slash < 0 { slash = len(importPath) } diff --git a/src/cmd/go/internal/load/match_test.go b/src/cmd/go/internal/load/match_test.go index ffc2b0234cc..b8d67dac742 100644 --- a/src/cmd/go/internal/load/match_test.go +++ b/src/cmd/go/internal/load/match_test.go @@ -139,7 +139,7 @@ func testStringPairs(t *testing.T, name string, tests []stringPairTest, f func(s func testPatterns(t *testing.T, name, tests string, fn func(string, string) bool) { var patterns []string for _, line := range strings.Split(tests, "\n") { - if i := strings.IndexByte(line, '#'); i >= 0 { + if i := strings.Index(line, "#"); i >= 0 { line = line[:i] } f := strings.Fields(line) diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 526e5a6767e..fc174737626 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -226,7 +226,7 @@ func (p *Package) copyBuild(pp *build.Package) { // their own code to $GOROOT instead of using $GOPATH, but we assume that // code will start with a domain name (dot in the first element). func isStandardImportPath(path string) bool { - i := strings.IndexByte(path, '/') + i := strings.Index(path, "/") if i < 0 { i = len(path) } diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 8bb6aa6040b..79d1e7b14a3 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -844,7 +844,7 @@ var zeros [512]byte var strdata []*sym.Symbol func addstrdata1(ctxt *Link, arg string) { - eq := strings.IndexByte(arg, '=') + eq := strings.Index(arg, "=") dot := strings.LastIndex(arg[:eq+1], ".") if eq < 0 || dot < 0 { Exitf("-X flag requires argument of the form importpath.name=value") diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index a45ad891cd8..00a076f2245 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -327,7 +327,7 @@ func (d *deadcodepass) flood() { } for i, m := range methodsigs { name := string(m) - name = name[:strings.IndexByte(name, '(')] + name = name[:strings.Index(name, "(")] if !strings.HasSuffix(methods[i].ifn().Name, name) { panic(fmt.Sprintf("%q relocation for %q does not match method %q", s.Name, methods[i].ifn().Name, name)) } diff --git a/src/cmd/link/internal/ld/go.go b/src/cmd/link/internal/ld/go.go index b69e1f3a411..4aa81895a91 100644 --- a/src/cmd/link/internal/ld/go.go +++ b/src/cmd/link/internal/ld/go.go @@ -181,7 +181,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { local = expandpkg(local, pkg) q = "" - if i := strings.IndexByte(remote, '#'); i >= 0 { + if i := strings.Index(remote, "#"); i >= 0 { remote, q = remote[:i], remote[i+1:] } s = ctxt.Syms.Lookup(local, 0) diff --git a/src/cmd/link/internal/ld/ld.go b/src/cmd/link/internal/ld/ld.go index f2a98e2d51a..d8939febfb5 100644 --- a/src/cmd/link/internal/ld/ld.go +++ b/src/cmd/link/internal/ld/ld.go @@ -61,13 +61,13 @@ func (ctxt *Link) readImportCfg(file string) { } var verb, args string - if i := strings.IndexByte(line, ' '); i < 0 { + if i := strings.Index(line, " "); i < 0 { verb = line } else { verb, args = line[:i], strings.TrimSpace(line[i+1:]) } var before, after string - if i := strings.IndexByte(args, '='); i >= 0 { + if i := strings.Index(args, "="); i >= 0 { before, after = args[:i], args[i+1:] } switch verb { diff --git a/src/cmd/vet/asmdecl.go b/src/cmd/vet/asmdecl.go index 1a9310204b3..b01d23d342b 100644 --- a/src/cmd/vet/asmdecl.go +++ b/src/cmd/vet/asmdecl.go @@ -678,7 +678,7 @@ func asmCheckVar(badf func(string, ...interface{}), fn *asmFunc, line, expr stri // Determine whether the match we're holding // is the first or second argument. - if strings.Index(line, expr) > strings.IndexByte(line, ',') { + if strings.Index(line, expr) > strings.Index(line, ",") { kind = dst } else { kind = src diff --git a/src/cmd/vet/print.go b/src/cmd/vet/print.go index f64e449f6d7..453a072565f 100644 --- a/src/cmd/vet/print.go +++ b/src/cmd/vet/print.go @@ -303,7 +303,7 @@ func (s *formatState) parseIndex() bool { start := s.nbytes s.scanNum() if s.nbytes == len(s.format) || s.nbytes == start || s.format[s.nbytes] != ']' { - end := strings.IndexByte(s.format, ']') + end := strings.Index(s.format, "]") if end < 0 { end = len(s.format) } diff --git a/src/cmd/vet/structtag.go b/src/cmd/vet/structtag.go index c3ec4310597..cfa816694e0 100644 --- a/src/cmd/vet/structtag.go +++ b/src/cmd/vet/structtag.go @@ -63,7 +63,7 @@ func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token // by containing a field named XMLName; see issue 18256. continue } - if i := strings.IndexByte(val, ','); i >= 0 { + if i := strings.Index(val, ","); i >= 0 { if key == "xml" { // Use a separate namespace for XML attributes. for _, opt := range strings.Split(val[i:], ",") { diff --git a/src/crypto/x509/pem_decrypt.go b/src/crypto/x509/pem_decrypt.go index 21eb4325b8d..0388d63e149 100644 --- a/src/crypto/x509/pem_decrypt.go +++ b/src/crypto/x509/pem_decrypt.go @@ -118,7 +118,7 @@ func DecryptPEMBlock(b *pem.Block, password []byte) ([]byte, error) { return nil, errors.New("x509: no DEK-Info header in block") } - idx := strings.IndexByte(dek, ',') + idx := strings.Index(dek, ",") if idx == -1 { return nil, errors.New("x509: malformed DEK-Info header") } diff --git a/src/crypto/x509/root_darwin_arm_gen.go b/src/crypto/x509/root_darwin_arm_gen.go index 53aef93c21f..fc2488adc6f 100644 --- a/src/crypto/x509/root_darwin_arm_gen.go +++ b/src/crypto/x509/root_darwin_arm_gen.go @@ -161,7 +161,7 @@ func fetchCertIDs() ([]certID, error) { } if strings.HasPrefix(ln, sn) { // extract hex value from parentheses. - id.serialNumber = ln[strings.IndexByte(ln, '(')+1 : len(ln)-1] + id.serialNumber = ln[strings.Index(ln, "(")+1 : len(ln)-1] continue } if strings.TrimSpace(ln) == "X509v3 Subject Key Identifier:" { diff --git a/src/debug/gosym/symtab.go b/src/debug/gosym/symtab.go index eab255a3596..fd8703b36bc 100644 --- a/src/debug/gosym/symtab.go +++ b/src/debug/gosym/symtab.go @@ -45,7 +45,7 @@ func (s *Sym) PackageName() string { pathend = 0 } - if i := strings.IndexByte(s.Name[pathend:], '.'); i != -1 { + if i := strings.Index(s.Name[pathend:], "."); i != -1 { return s.Name[:pathend+i] } return "" @@ -58,7 +58,7 @@ func (s *Sym) ReceiverName() string { if pathend < 0 { pathend = 0 } - l := strings.IndexByte(s.Name[pathend:], '.') + l := strings.Index(s.Name[pathend:], ".") r := strings.LastIndexByte(s.Name[pathend:], '.') if l == -1 || r == -1 || l == r { return "" diff --git a/src/encoding/json/tags.go b/src/encoding/json/tags.go index 6a8d03a5df2..c38fd5102f6 100644 --- a/src/encoding/json/tags.go +++ b/src/encoding/json/tags.go @@ -15,7 +15,7 @@ type tagOptions string // parseTag splits a struct field's json tag into its name and // comma-separated options. func parseTag(tag string) (string, tagOptions) { - if idx := strings.IndexByte(tag, ','); idx != -1 { + if idx := strings.Index(tag, ","); idx != -1 { return tag[:idx], tagOptions(tag[idx+1:]) } return tag, tagOptions("") @@ -31,7 +31,7 @@ func (o tagOptions) Contains(optionName string) bool { s := string(o) for s != "" { var next string - i := strings.IndexByte(s, ',') + i := strings.Index(s, ",") if i >= 0 { s, next = s[:i], s[i+1:] } diff --git a/src/encoding/xml/typeinfo.go b/src/encoding/xml/typeinfo.go index b3346d304ef..2e7ae935a8b 100644 --- a/src/encoding/xml/typeinfo.go +++ b/src/encoding/xml/typeinfo.go @@ -115,7 +115,7 @@ func structFieldInfo(typ reflect.Type, f *reflect.StructField) (*fieldInfo, erro // Split the tag from the xml namespace if necessary. tag := f.Tag.Get("xml") - if i := strings.IndexByte(tag, ' '); i >= 0 { + if i := strings.Index(tag, " "); i >= 0 { finfo.xmlns, tag = tag[:i], tag[i+1:] } diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go index 27b871649be..be90b62c9a0 100644 --- a/src/encoding/xml/xml.go +++ b/src/encoding/xml/xml.go @@ -1161,7 +1161,7 @@ func (d *Decoder) nsname() (name Name, ok bool) { if !ok { return } - i := strings.IndexByte(s, ':') + i := strings.Index(s, ":") if i < 0 { name.Local = s } else { diff --git a/src/go/build/build.go b/src/go/build/build.go index c449ad95e80..8e92b2f5d12 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -1247,7 +1247,7 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) // Split at colon. line = strings.TrimSpace(line[4:]) - i := strings.IndexByte(line, ':') + i := strings.Index(line, ":") if i < 0 { return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig) } @@ -1462,7 +1462,7 @@ func (ctxt *Context) match(name string, allTags map[string]bool) bool { } return false } - if i := strings.IndexByte(name, ','); i >= 0 { + if i := strings.Index(name, ","); i >= 0 { // comma-separated list ok1 := ctxt.match(name[:i], allTags) ok2 := ctxt.match(name[i+1:], allTags) @@ -1526,7 +1526,7 @@ func (ctxt *Context) match(name string, allTags map[string]bool) bool { // // An exception: if GOOS=android, then files with GOOS=linux are also matched. func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool { - if dot := strings.IndexByte(name, '.'); dot != -1 { + if dot := strings.Index(name, "."); dot != -1 { name = name[:dot] } @@ -1537,7 +1537,7 @@ func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool { // systems, such as android, to arrive without breaking existing code with // innocuous source code in "android.go". The easiest fix: cut everything // in the name before the initial _. - i := strings.IndexByte(name, '_') + i := strings.Index(name, "_") if i < 0 { return true } diff --git a/src/go/printer/printer.go b/src/go/printer/printer.go index 6a954e21fee..2b8dc19fba9 100644 --- a/src/go/printer/printer.go +++ b/src/go/printer/printer.go @@ -537,7 +537,7 @@ func stripCommonPrefix(lines []string) { * Check for vertical "line of stars" and correct prefix accordingly. */ lineOfStars := false - if i := strings.IndexByte(prefix, '*'); i >= 0 { + if i := strings.Index(prefix, "*"); i >= 0 { // Line of stars present. if i > 0 && prefix[i-1] == ' ' { i-- // remove trailing blank from prefix so stars remain aligned diff --git a/src/html/template/js.go b/src/html/template/js.go index d80ead5ed25..239395f8d3a 100644 --- a/src/html/template/js.go +++ b/src/html/template/js.go @@ -374,7 +374,7 @@ func isJSType(mimeType string) bool { // https://www.ietf.org/rfc/rfc4627.txt mimeType = strings.ToLower(mimeType) // discard parameters - if i := strings.IndexByte(mimeType, ';'); i >= 0 { + if i := strings.Index(mimeType, ";"); i >= 0 { mimeType = mimeType[:i] } mimeType = strings.TrimSpace(mimeType) diff --git a/src/math/big/ratconv.go b/src/math/big/ratconv.go index 7aed289218c..157d8d006d4 100644 --- a/src/math/big/ratconv.go +++ b/src/math/big/ratconv.go @@ -49,7 +49,7 @@ func (z *Rat) SetString(s string) (*Rat, bool) { // len(s) > 0 // parse fraction a/b, if any - if sep := strings.IndexByte(s, '/'); sep >= 0 { + if sep := strings.Index(s, "/"); sep >= 0 { if _, ok := z.a.SetString(s[:sep], 0); !ok { return nil, false } diff --git a/src/mime/encodedword.go b/src/mime/encodedword.go index bb49d65873a..99eb432f54e 100644 --- a/src/mime/encodedword.go +++ b/src/mime/encodedword.go @@ -257,7 +257,7 @@ func (d *WordDecoder) DecodeHeader(header string) (string, error) { } cur := start + len("=?") - i := strings.IndexByte(header[cur:], '?') + i := strings.Index(header[cur:], "?") if i == -1 { break } diff --git a/src/mime/mediatype.go b/src/mime/mediatype.go index 7ec67cd584e..b8a83d6f79c 100644 --- a/src/mime/mediatype.go +++ b/src/mime/mediatype.go @@ -20,7 +20,7 @@ import ( // FormatMediaType returns the empty string. func FormatMediaType(t string, param map[string]string) string { var b bytes.Buffer - if slash := strings.IndexByte(t, '/'); slash == -1 { + if slash := strings.Index(t, "/"); slash == -1 { if !isToken(t) { return "" } @@ -110,7 +110,7 @@ var ErrInvalidMediaParameter = errors.New("mime: invalid media parameter") // The returned map, params, maps from the lowercase // attribute to the attribute value with its case preserved. func ParseMediaType(v string) (mediatype string, params map[string]string, err error) { - i := strings.IndexByte(v, ';') + i := strings.Index(v, ";") if i == -1 { i = len(v) } @@ -146,7 +146,7 @@ func ParseMediaType(v string) (mediatype string, params map[string]string, err e } pmap := params - if idx := strings.IndexByte(key, '*'); idx != -1 { + if idx := strings.Index(key, "*"); idx != -1 { baseName := key[:idx] if continuation == nil { continuation = make(map[string]map[string]string) diff --git a/src/net/http/cgi/child.go b/src/net/http/cgi/child.go index 2c762bdba9e..ec101088219 100644 --- a/src/net/http/cgi/child.go +++ b/src/net/http/cgi/child.go @@ -40,7 +40,7 @@ func Request() (*http.Request, error) { func envMap(env []string) map[string]string { m := make(map[string]string) for _, kv := range env { - if idx := strings.IndexByte(kv, '='); idx != -1 { + if idx := strings.Index(kv, "="); idx != -1 { m[kv[:idx]] = kv[idx+1:] } } diff --git a/src/net/http/cookie.go b/src/net/http/cookie.go index 6642a246954..38b1b3630e2 100644 --- a/src/net/http/cookie.go +++ b/src/net/http/cookie.go @@ -50,7 +50,7 @@ func readSetCookies(h Header) []*Cookie { continue } parts[0] = strings.TrimSpace(parts[0]) - j := strings.IndexByte(parts[0], '=') + j := strings.Index(parts[0], "=") if j < 0 { continue } @@ -74,7 +74,7 @@ func readSetCookies(h Header) []*Cookie { } attr, val := parts[i], "" - if j := strings.IndexByte(attr, '='); j >= 0 { + if j := strings.Index(attr, "="); j >= 0 { attr, val = attr[:j], attr[j+1:] } lowerAttr := strings.ToLower(attr) @@ -214,7 +214,7 @@ func readCookies(h Header, filter string) []*Cookie { continue } name, val := parts[i], "" - if j := strings.IndexByte(name, '='); j >= 0 { + if j := strings.Index(name, "="); j >= 0 { name, val = name[:j], name[j+1:] } if !isCookieNameValid(name) { diff --git a/src/net/http/fs.go b/src/net/http/fs.go index e17a6d8f3f8..ecad14ac1e4 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -748,7 +748,7 @@ func parseRange(s string, size int64) ([]httpRange, error) { if ra == "" { continue } - i := strings.IndexByte(ra, '-') + i := strings.Index(ra, "-") if i < 0 { return nil, errors.New("invalid range") } diff --git a/src/net/http/request.go b/src/net/http/request.go index e3845176686..801d00ef2f0 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -712,7 +712,7 @@ func ParseHTTPVersion(vers string) (major, minor int, ok bool) { if !strings.HasPrefix(vers, "HTTP/") { return 0, 0, false } - dot := strings.IndexByte(vers, '.') + dot := strings.Index(vers, ".") if dot < 0 { return 0, 0, false } @@ -880,8 +880,8 @@ func (r *Request) SetBasicAuth(username, password string) { // parseRequestLine parses "GET /foo HTTP/1.1" into its three parts. func parseRequestLine(line string) (method, requestURI, proto string, ok bool) { - s1 := strings.IndexByte(line, ' ') - s2 := strings.IndexByte(line[s1+1:], ' ') + s1 := strings.Index(line, " ") + s2 := strings.Index(line[s1+1:], " ") if s1 < 0 || s2 < 0 { return } diff --git a/src/net/http/server.go b/src/net/http/server.go index 60575926bd4..cfc6654ff43 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2002,7 +2002,7 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) { } var query string - if i := strings.IndexByte(url, '?'); i != -1 { + if i := strings.Index(url, "?"); i != -1 { url, query = url[:i], url[i:] } diff --git a/src/net/lookup_test.go b/src/net/lookup_test.go index fc184154da3..68a7abe95df 100644 --- a/src/net/lookup_test.go +++ b/src/net/lookup_test.go @@ -475,7 +475,7 @@ func TestLookupDotsWithLocalSource(t *testing.T) { } loop: for i, name := range names { - if strings.IndexByte(name, '.') == len(name)-1 { // "localhost" not "localhost." + if strings.Index(name, ".") == len(name)-1 { // "localhost" not "localhost." for j := range names { if j == i { continue diff --git a/src/net/url/url.go b/src/net/url/url.go index a317d096f26..53122c79cd9 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -505,8 +505,8 @@ func parse(rawurl string, viaRequest bool) (*URL, error) { // RFC 3986, ยง3.3: // In addition, a URI reference (Section 4.1) may be a relative-path reference, // in which case the first path segment cannot contain a colon (":") character. - colon := strings.IndexByte(rest, ':') - slash := strings.IndexByte(rest, '/') + colon := strings.Index(rest, ":") + slash := strings.Index(rest, "/") if colon >= 0 && (slash < 0 || colon < slash) { // First path segment has colon. Not allowed in relative URL. return nil, errors.New("first path segment in URL cannot contain colon") @@ -830,7 +830,7 @@ func parseQuery(m Values, query string) (err error) { continue } value := "" - if i := strings.IndexByte(key, '='); i >= 0 { + if i := strings.Index(key, "="); i >= 0 { key, value = key[:i], key[i+1:] } key, err1 := QueryUnescape(key) diff --git a/src/os/env_test.go b/src/os/env_test.go index d51097e20d1..e5749f0e899 100644 --- a/src/os/env_test.go +++ b/src/os/env_test.go @@ -104,7 +104,7 @@ func TestClearenv(t *testing.T) { for _, pair := range origEnv { // Environment variables on Windows can begin with = // http://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx - i := strings.IndexByte(pair[1:], '=') + 1 + i := strings.Index(pair[1:], "=") + 1 if err := Setenv(pair[:i], pair[i+1:]); err != nil { t.Errorf("Setenv(%q, %q) failed during reset: %v", pair[:i], pair[i+1:], err) } diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index bd07a6a73d2..b0fe14d6fdd 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -687,7 +687,7 @@ func dedupEnvCase(caseInsensitive bool, env []string) []string { out := make([]string, 0, len(env)) saw := map[string]int{} // key => index into out for _, kv := range env { - eq := strings.IndexByte(kv, '=') + eq := strings.Index(kv, "=") if eq < 0 { out = append(out, kv) continue diff --git a/src/os/os_test.go b/src/os/os_test.go index 5397dbe148e..86f8652a2e6 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -1523,7 +1523,7 @@ func TestHostname(t *testing.T) { } want := runBinHostname(t) if hostname != want { - i := strings.IndexByte(hostname, '.') + i := strings.Index(hostname, ".") if i < 0 || hostname[0:i] != want { t.Errorf("Hostname() = %q, want %q", hostname, want) } diff --git a/src/os/user/cgo_lookup_unix.go b/src/os/user/cgo_lookup_unix.go index 7d92cb21381..6f66851bbbc 100644 --- a/src/os/user/cgo_lookup_unix.go +++ b/src/os/user/cgo_lookup_unix.go @@ -124,7 +124,7 @@ func buildUser(pwd *C.struct_passwd) *User { // say: "It is expected to be a comma separated list of // personal data where the first item is the full name of the // user." - if i := strings.IndexByte(u.Name, ','); i >= 0 { + if i := strings.Index(u.Name, ","); i >= 0 { u.Name = u.Name[:i] } return u diff --git a/src/os/user/lookup_unix.go b/src/os/user/lookup_unix.go index f4c2f670d20..5f34ba8611c 100644 --- a/src/os/user/lookup_unix.go +++ b/src/os/user/lookup_unix.go @@ -131,7 +131,7 @@ func matchUserIndexValue(value string, idx int) lineFunc { // say: "It is expected to be a comma separated list of // personal data where the first item is the full name of the // user." - if i := strings.IndexByte(u.Name, ','); i >= 0 { + if i := strings.Index(u.Name, ","); i >= 0 { u.Name = u.Name[:i] } return u, nil diff --git a/src/regexp/exec_test.go b/src/regexp/exec_test.go index 5b827a528d7..5f8e747b17b 100644 --- a/src/regexp/exec_test.go +++ b/src/regexp/exec_test.go @@ -294,7 +294,7 @@ func parseResult(t *testing.T, file string, lineno int, res string) []int { out[n] = -1 out[n+1] = -1 } else { - k := strings.IndexByte(pair, '-') + k := strings.Index(pair, "-") if k < 0 { t.Fatalf("%s:%d: invalid pair %s", file, lineno, pair) } @@ -457,7 +457,7 @@ Reading: continue Reading } case ':': - i := strings.IndexByte(flag[1:], ':') + i := strings.Index(flag[1:], ":") if i < 0 { t.Logf("skip: %s", line) continue Reading diff --git a/src/regexp/regexp.go b/src/regexp/regexp.go index f8643e5a547..b1af23e8504 100644 --- a/src/regexp/regexp.go +++ b/src/regexp/regexp.go @@ -829,7 +829,7 @@ func (re *Regexp) ExpandString(dst []byte, template string, src string, match [] func (re *Regexp) expand(dst []byte, template string, bsrc []byte, src string, match []int) []byte { for len(template) > 0 { - i := strings.IndexByte(template, '$') + i := strings.Index(template, "$") if i < 0 { break } diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 64325eb6bb6..955964c721e 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -213,7 +213,7 @@ func profileOk(t *testing.T, need []string, prof bytes.Buffer, duration time.Dur fprintStack(&buf, stk) samples += count for i, name := range need { - if semi := strings.IndexByte(name, ';'); semi > -1 { + if semi := strings.Index(name, ";"); semi > -1 { kv := strings.SplitN(name[semi+1:], "=", 2) if len(kv) != 2 || !contains(labels[kv[0]], kv[1]) { continue diff --git a/src/unicode/maketables.go b/src/unicode/maketables.go index dcfd471b05c..9a92a0130a0 100644 --- a/src/unicode/maketables.go +++ b/src/unicode/maketables.go @@ -680,7 +680,7 @@ func verifyRange(name string, inCategory Op, table *unicode.RangeTable) { } func parseScript(line string, scripts map[string][]Script) { - comment := strings.IndexByte(line, '#') + comment := strings.Index(line, "#") if comment >= 0 { line = line[0:comment] }