diff --git a/src/go/build/build.go b/src/go/build/build.go index 4bc34086b35f1c..76b7ab50412283 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -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. diff --git a/src/go/printer/comment.go b/src/go/printer/comment.go index 76dd31efc73a8d..9012714939406b 100644 --- a/src/go/printer/comment.go +++ b/src/go/printer/comment.go @@ -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()