diff --git a/cmd/bundle/main.go b/cmd/bundle/main.go
index fa73eb8..d6b5909 100644
--- a/cmd/bundle/main.go
+++ b/cmd/bundle/main.go
@@ -241,7 +241,7 @@
// Concatenate package comments from all files...
for _, f := range pkg.Syntax {
if doc := f.Doc.Text(); strings.TrimSpace(doc) != "" {
- for _, line := range strings.Split(doc, "\n") {
+ for line := range strings.SplitSeq(doc, "\n") {
fmt.Fprintf(&out, "// %s\n", line)
}
}
diff --git a/cmd/compilebench/main.go b/cmd/compilebench/main.go
index a1805fd..74ab286 100644
--- a/cmd/compilebench/main.go
+++ b/cmd/compilebench/main.go
@@ -511,7 +511,7 @@
if err != nil {
log.Print("cannot find memory profile after compilation")
}
- for _, line := range strings.Split(string(out), "\n") {
+ for line := range strings.SplitSeq(string(out), "\n") {
f := strings.Fields(line)
if len(f) < 4 || f[0] != "#" || f[2] != "=" {
continue
diff --git a/cmd/digraph/digraph_test.go b/cmd/digraph/digraph_test.go
index 7c96702..d244615 100644
--- a/cmd/digraph/digraph_test.go
+++ b/cmd/digraph/digraph_test.go
@@ -252,7 +252,7 @@
got = strings.Join(lines[1:], "\n")
var oneMatch bool
- for _, want := range strings.Split(test.wantAnyOf, "|") {
+ for want := range strings.SplitSeq(test.wantAnyOf, "|") {
if got == want {
oneMatch = true
}
diff --git a/cmd/fiximports/main.go b/cmd/fiximports/main.go
index a528402..1ce8d01 100644
--- a/cmd/fiximports/main.go
+++ b/cmd/fiximports/main.go
@@ -175,7 +175,7 @@
matchPrefix bool
}
var replace []replaceItem
- for _, pair := range strings.Split(*replaceFlag, ",") {
+ for pair := range strings.SplitSeq(*replaceFlag, ",") {
if pair == "" {
continue
}
diff --git a/cmd/go-contrib-init/contrib.go b/cmd/go-contrib-init/contrib.go
index 0ab93c9..3fabb34 100644
--- a/cmd/go-contrib-init/contrib.go
+++ b/cmd/go-contrib-init/contrib.go
@@ -191,7 +191,7 @@
log.Fatalf("Error running git remote -v: %v", msg)
}
matches := 0
- for _, line := range strings.Split(string(remotes), "\n") {
+ for line := range strings.SplitSeq(string(remotes), "\n") {
line = strings.TrimSpace(line)
if !strings.HasPrefix(line, "origin") {
continue
diff --git a/cmd/html2article/conv.go b/cmd/html2article/conv.go
index e294643..ae8129b 100644
--- a/cmd/html2article/conv.go
+++ b/cmd/html2article/conv.go
@@ -132,7 +132,7 @@
}
func indent(buf *bytes.Buffer, s string) {
- for _, l := range strings.Split(s, "\n") {
+ for l := range strings.SplitSeq(s, "\n") {
if l != "" {
buf.WriteByte('\t')
buf.WriteString(l)
@@ -143,7 +143,7 @@
func unwrap(buf *bytes.Buffer, s string) {
var cont bool
- for _, l := range strings.Split(s, "\n") {
+ for l := range strings.SplitSeq(s, "\n") {
l = strings.TrimSpace(l)
if len(l) == 0 {
if cont {
diff --git a/cmd/present2md/main.go b/cmd/present2md/main.go
index e23bb33..4a298b7 100644
--- a/cmd/present2md/main.go
+++ b/cmd/present2md/main.go
@@ -200,7 +200,7 @@
lines = lines[1:]
}
if elem.Pre {
- for _, line := range strings.Split(strings.TrimRight(elem.Raw, "\n"), "\n") {
+ for line := range strings.SplitSeq(strings.TrimRight(elem.Raw, "\n"), "\n") {
if line == "" {
fmt.Fprintf(w, "\n")
} else {
diff --git a/cmd/signature-fuzzer/internal/fuzz-generator/generator.go b/cmd/signature-fuzzer/internal/fuzz-generator/generator.go
index 261dd6c..7f4fea4 100644
--- a/cmd/signature-fuzzer/internal/fuzz-generator/generator.go
+++ b/cmd/signature-fuzzer/internal/fuzz-generator/generator.go
@@ -409,8 +409,7 @@
}
verb(1, "%s mask is %s", tag, arg)
m := make(map[int]int)
- ss := strings.Split(arg, ":")
- for _, s := range ss {
+ for s := range strings.SplitSeq(arg, ":") {
if strings.Contains(s, "-") {
rng := strings.Split(s, "-")
if len(rng) != 2 {
diff --git a/go/analysis/analysistest/analysistest.go b/go/analysis/analysistest/analysistest.go
index 5cc6d8c..63ae278 100644
--- a/go/analysis/analysistest/analysistest.go
+++ b/go/analysis/analysistest/analysistest.go
@@ -590,7 +590,7 @@
}
filename := sanitize(gopath, filename)
linenum := 0
- for _, line := range strings.Split(string(data), "\n") {
+ for line := range strings.SplitSeq(string(data), "\n") {
linenum++
// Hack: treat a comment of the form "//...// want..."
diff --git a/go/analysis/internal/checker/fix_test.go b/go/analysis/internal/checker/fix_test.go
index d144de4..4674bb0 100644
--- a/go/analysis/internal/checker/fix_test.go
+++ b/go/analysis/internal/checker/fix_test.go
@@ -338,7 +338,7 @@
case "skip":
config := fmt.Sprintf("GOOS=%s GOARCH=%s", runtime.GOOS, runtime.GOARCH)
- for _, word := range strings.Fields(rest) {
+ for word := range strings.FieldsSeq(rest) {
if strings.Contains(config, word) {
t.Skip(word)
}
diff --git a/go/analysis/passes/asmdecl/asmdecl.go b/go/analysis/passes/asmdecl/asmdecl.go
index 1aa7afb..efbf05d 100644
--- a/go/analysis/passes/asmdecl/asmdecl.go
+++ b/go/analysis/passes/asmdecl/asmdecl.go
@@ -237,7 +237,7 @@
// so accumulate them all and then prefer the one that
// matches build.Default.GOARCH.
var archCandidates []*asmArch
- for _, fld := range strings.Fields(m[1]) {
+ for fld := range strings.FieldsSeq(m[1]) {
for _, a := range arches {
if a.name == fld {
archCandidates = append(archCandidates, a)
diff --git a/go/analysis/passes/buildtag/buildtag.go b/go/analysis/passes/buildtag/buildtag.go
index 6c7a0df..6e32f29 100644
--- a/go/analysis/passes/buildtag/buildtag.go
+++ b/go/analysis/passes/buildtag/buildtag.go
@@ -298,7 +298,7 @@
fields := strings.Fields(line[len("//"):])
// IsPlusBuildConstraint check above implies fields[0] == "+build"
for _, arg := range fields[1:] {
- for _, elem := range strings.Split(arg, ",") {
+ for elem := range strings.SplitSeq(arg, ",") {
if strings.HasPrefix(elem, "!!") {
check.pass.Reportf(pos, "invalid double negative in build constraint: %s", arg)
check.crossCheck = false
diff --git a/go/analysis/passes/printf/printf.go b/go/analysis/passes/printf/printf.go
index 9ad18a0..f008eca 100644
--- a/go/analysis/passes/printf/printf.go
+++ b/go/analysis/passes/printf/printf.go
@@ -992,7 +992,7 @@
}
func (ss stringSet) Set(flag string) error {
- for _, name := range strings.Split(flag, ",") {
+ for name := range strings.SplitSeq(flag, ",") {
if len(name) == 0 {
return fmt.Errorf("empty string")
}
diff --git a/go/analysis/passes/unusedresult/unusedresult.go b/go/analysis/passes/unusedresult/unusedresult.go
index 556ffed..ed4cf7a 100644
--- a/go/analysis/passes/unusedresult/unusedresult.go
+++ b/go/analysis/passes/unusedresult/unusedresult.go
@@ -188,7 +188,7 @@
func (ss *stringSetFlag) Set(s string) error {
m := make(map[string]bool) // clobber previous value
if s != "" {
- for _, name := range strings.Split(s, ",") {
+ for name := range strings.SplitSeq(s, ",") {
if name == "" {
continue // TODO: report error? proceed?
}
diff --git a/go/buildutil/tags.go b/go/buildutil/tags.go
index 410c8e7..f66cd5d 100644
--- a/go/buildutil/tags.go
+++ b/go/buildutil/tags.go
@@ -43,7 +43,7 @@
// Starting in Go 1.13, the -tags flag is a comma-separated list of build tags.
*v = []string{}
- for _, s := range strings.Split(s, ",") {
+ for s := range strings.SplitSeq(s, ",") {
if s != "" {
*v = append(*v, s)
}
diff --git a/go/callgraph/rta/rta_test.go b/go/callgraph/rta/rta_test.go
index 8cfc73e..7b273cc 100644
--- a/go/callgraph/rta/rta_test.go
+++ b/go/callgraph/rta/rta_test.go
@@ -120,7 +120,7 @@
wantReachable = make(map[string]bool)
wantRtype = make(map[string]bool)
)
- for _, line := range strings.Split(want, "\n") {
+ for line := range strings.SplitSeq(want, "\n") {
linenum++
orig := line
bad := func() {
diff --git a/go/ssa/interp/rangefunc_test.go b/go/ssa/interp/rangefunc_test.go
index 434468f..fe1f327 100644
--- a/go/ssa/interp/rangefunc_test.go
+++ b/go/ssa/interp/rangefunc_test.go
@@ -108,7 +108,7 @@
},
}
got := make(map[string][]string)
- for _, ln := range strings.Split(out, "\n") {
+ for ln := range strings.SplitSeq(out, "\n") {
if ind := strings.Index(ln, " \t "); ind >= 0 {
n, m := ln[:ind], ln[ind+3:]
got[n] = append(got[n], m)
diff --git a/internal/analysisinternal/extractdoc.go b/internal/analysisinternal/extractdoc.go
index 3950772..bfb5900 100644
--- a/internal/analysisinternal/extractdoc.go
+++ b/internal/analysisinternal/extractdoc.go
@@ -97,7 +97,7 @@
if f.Doc == nil {
return "", fmt.Errorf("Go source file has no package doc comment")
}
- for _, section := range strings.Split(f.Doc.Text(), "\n# ") {
+ for section := range strings.SplitSeq(f.Doc.Text(), "\n# ") {
if body := strings.TrimPrefix(section, "Analyzer "+name); body != section &&
body != "" &&
body[0] == '\r' || body[0] == '\n' {
diff --git a/internal/astutil/comment.go b/internal/astutil/comment.go
index ee4be23..c3a256c 100644
--- a/internal/astutil/comment.go
+++ b/internal/astutil/comment.go
@@ -15,7 +15,7 @@
// https://go.dev/wiki/Deprecated, or "" if the documented symbol is not
// deprecated.
func Deprecation(doc *ast.CommentGroup) string {
- for _, p := range strings.Split(doc.Text(), "\n\n") {
+ for p := range strings.SplitSeq(doc.Text(), "\n\n") {
// There is still some ambiguity for deprecation message. This function
// only returns the paragraph introduced by "Deprecated: ". More
// information related to the deprecation may follow in additional
diff --git a/internal/goroot/importcfg.go b/internal/goroot/importcfg.go
index f1cd28e..908e8e7 100644
--- a/internal/goroot/importcfg.go
+++ b/internal/goroot/importcfg.go
@@ -51,7 +51,7 @@
if err != nil {
stdlibPkgfileErr = err
}
- for _, line := range strings.Split(string(output), "\n") {
+ for line := range strings.SplitSeq(string(output), "\n") {
if line == "" {
continue
}
diff --git a/internal/imports/fix.go b/internal/imports/fix.go
index 6013f1c..1b4dc0c 100644
--- a/internal/imports/fix.go
+++ b/internal/imports/fix.go
@@ -42,7 +42,7 @@
if localPrefix == "" {
return
}
- for _, p := range strings.Split(localPrefix, ",") {
+ for p := range strings.SplitSeq(localPrefix, ",") {
if strings.HasPrefix(importPath, p) || strings.TrimSuffix(p, "/") == importPath {
return 3, true
}
diff --git a/internal/mcp/internal/util/util.go b/internal/mcp/internal/util/util.go
index 8db176d..d48412d 100644
--- a/internal/mcp/internal/util/util.go
+++ b/internal/mcp/internal/util/util.go
@@ -67,7 +67,7 @@
}
if len(rest) > 0 {
info.Settings = map[string]bool{}
- for _, s := range strings.Split(rest, ",") {
+ for s := range strings.SplitSeq(rest, ",") {
info.Settings[s] = true
}
}
diff --git a/internal/modindex/symbols.go b/internal/modindex/symbols.go
index fe24db9..8e9702d 100644
--- a/internal/modindex/symbols.go
+++ b/internal/modindex/symbols.go
@@ -206,8 +206,7 @@
// go.dev/wiki/Deprecated Paragraph starting 'Deprecated:'
// This code fails for /* Deprecated: */, but it's the code from
// gopls/internal/analysis/deprecated
- lines := strings.Split(doc.Text(), "\n\n")
- for _, line := range lines {
+ for line := range strings.SplitSeq(doc.Text(), "\n\n") {
if strings.HasPrefix(line, "Deprecated:") {
return true
}
diff --git a/internal/refactor/inline/free_test.go b/internal/refactor/inline/free_test.go
index 1922bfb..973e8af 100644
--- a/internal/refactor/inline/free_test.go
+++ b/internal/refactor/inline/free_test.go
@@ -215,7 +215,7 @@
n := f.Decls[0].(*ast.FuncDecl).Body
got := map[string]bool{}
want := map[string]bool{}
- for _, n := range strings.Fields(test.want) {
+ for n := range strings.FieldsSeq(test.want) {
want[n] = true
}
diff --git a/internal/testenv/testenv.go b/internal/testenv/testenv.go
index fa53f37..aa39bed 100644
--- a/internal/testenv/testenv.go
+++ b/internal/testenv/testenv.go
@@ -530,7 +530,7 @@
goexp := os.Getenv("GOEXPERIMENT")
set := false
- for _, f := range strings.Split(goexp, ",") {
+ for f := range strings.SplitSeq(goexp, ",") {
if f == "" {
continue
}