Skip to content

Commit f4abeae

Browse files
qiulaidongfengtimothy-king
authored andcommitted
go/analysis/passes/directive: use strings.Cut
Change-Id: Ie3273daca752b8c22443edfdbde635a9f61577a3 GitHub-Last-Rev: 1e19b61 GitHub-Pull-Request: golang#450 Reviewed-on: https://go-review.googlesource.com/c/tools/+/530696 Reviewed-by: Tim King <taking@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Tim King <taking@google.com>
1 parent c42ed47 commit f4abeae

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

go/analysis/passes/directive/directive.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (check *checker) nonGoFile(pos token.Pos, fullText string) {
124124
for text != "" {
125125
offset := len(fullText) - len(text)
126126
var line string
127-
line, text, _ = stringsCut(text, "\n")
127+
line, text, _ = strings.Cut(text, "\n")
128128

129129
if !inStar && strings.HasPrefix(line, "//") {
130130
check.comment(pos+token.Pos(offset), line)
@@ -137,7 +137,7 @@ func (check *checker) nonGoFile(pos token.Pos, fullText string) {
137137
line = strings.TrimSpace(line)
138138
if inStar {
139139
var ok bool
140-
_, line, ok = stringsCut(line, "*/")
140+
_, line, ok = strings.Cut(line, "*/")
141141
if !ok {
142142
break
143143
}
@@ -200,14 +200,6 @@ func (check *checker) comment(pos token.Pos, line string) {
200200
}
201201
}
202202

203-
// Go 1.18 strings.Cut.
204-
func stringsCut(s, sep string) (before, after string, found bool) {
205-
if i := strings.Index(s, sep); i >= 0 {
206-
return s[:i], s[i+len(sep):], true
207-
}
208-
return s, "", false
209-
}
210-
211203
// Go 1.20 strings.CutPrefix.
212204
func stringsCutPrefix(s, prefix string) (after string, found bool) {
213205
if !strings.HasPrefix(s, prefix) {

0 commit comments

Comments
 (0)