]> Cypherpunks repositories - gostls13.git/commitdiff
all: use strings.CutPrefix
authorcui fliter <imcusg@gmail.com>
Tue, 27 Sep 2022 01:31:31 +0000 (01:31 +0000)
committerBenny Siegert <bsiegert@gmail.com>
Tue, 27 Sep 2022 07:35:19 +0000 (07:35 +0000)
Updates #42537

Change-Id: Ice23d7d36bbede27551cbc086119694f6a3b5e4a
GitHub-Last-Rev: 0d65208313ea318725159186fad045fc6400fb25
GitHub-Pull-Request: golang/go#55347
Reviewed-on: https://go-review.googlesource.com/c/go/+/432895
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/go/build/build.go
src/go/printer/comment.go

index 36d9165125a5557457816ce6173e7bbec13564bc..bf779da99268c0772cee84b75449f9c5bee6fb05 100644 (file)
@@ -179,10 +179,11 @@ func hasSubdir(root, dir string) (rel string, ok bool) {
                root += sep
        }
        dir = filepath.Clean(dir)
-       if !strings.HasPrefix(dir, root) {
+       after, found := strings.CutPrefix(dir, root)
+       if !found {
                return "", false
        }
-       return filepath.ToSlash(dir[len(root):]), true
+       return filepath.ToSlash(after), true
 }
 
 // readDir calls ctxt.ReadDir (if not nil) or else os.ReadDir.
index 76dd31efc73a8d59b60547400e4a36b1a02d1e04..9012714939406b8a0dd1d0d477e2195b44426a92 100644 (file)
@@ -36,15 +36,16 @@ func formatDocComment(list []*ast.Comment) []*ast.Comment {
                kind = "//"
                var b strings.Builder
                for _, c := range list {
-                       if !strings.HasPrefix(c.Text, "//") {
+                       after, found := strings.CutPrefix(c.Text, "//")
+                       if !found {
                                return list
                        }
                        // Accumulate //go:build etc lines separately.
-                       if isDirective(c.Text[2:]) {
+                       if isDirective(after) {
                                directives = append(directives, c)
                                continue
                        }
-                       b.WriteString(strings.TrimPrefix(c.Text[2:], " "))
+                       b.WriteString(strings.TrimPrefix(after, " "))
                        b.WriteString("\n")
                }
                text = b.String()