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>
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.
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()