mirror of
https://github.com/golang/go
synced 2024-11-17 21:04:43 -07:00
all: use strings.CutPrefix
Updates #42537
Change-Id: Ice23d7d36bbede27551cbc086119694f6a3b5e4a
GitHub-Last-Rev: 0d65208313
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>
This commit is contained in:
parent
17f83e3473
commit
361f5eba9f
@ -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.
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user