aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/doc
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-09-22 10:46:32 -0400
committerRuss Cox <rsc@golang.org>2021-10-06 15:53:04 +0000
commit4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee (patch)
tree1e850efb295d4c5f0589e46bd8d9f1930d4af0b5 /src/cmd/doc
parent8e36ab055162efa6f67f3b9ee62f625ac8874901 (diff)
downloadgo-4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee.tar.gz
go-4d8db00641cc9ff4f44de7df9b8c4f4a4f9416ee.zip
all: use bytes.Cut, strings.Cut
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/doc')
-rw-r--r--src/cmd/doc/dirs.go6
-rw-r--r--src/cmd/doc/pkg.go4
2 files changed, 2 insertions, 8 deletions
diff --git a/src/cmd/doc/dirs.go b/src/cmd/doc/dirs.go
index 661624cfe4..f27af1d27b 100644
--- a/src/cmd/doc/dirs.go
+++ b/src/cmd/doc/dirs.go
@@ -221,11 +221,7 @@ func findCodeRoots() []Dir {
cmd.Stderr = os.Stderr
out, _ := cmd.Output()
for _, line := range strings.Split(string(out), "\n") {
- i := strings.Index(line, "\t")
- if i < 0 {
- continue
- }
- path, dir := line[:i], line[i+1:]
+ path, dir, _ := strings.Cut(line, "\t")
if dir != "" {
list = append(list, Dir{importPath: path, dir: dir, inModule: true})
}
diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go
index 587f0bdc14..822c9e16f8 100644
--- a/src/cmd/doc/pkg.go
+++ b/src/cmd/doc/pkg.go
@@ -315,9 +315,7 @@ func (pkg *Package) oneLineNodeDepth(node ast.Node, depth int) string {
recv = "(" + recv + ") "
}
fnc := pkg.oneLineNodeDepth(n.Type, depth)
- if strings.Index(fnc, "func") == 0 {
- fnc = fnc[4:]
- }
+ fnc = strings.TrimPrefix(fnc, "func")
return fmt.Sprintf("func %s%s%s", recv, name, fnc)
case *ast.TypeSpec: