Skip to content

Commit 5715d73

Browse files
mrclmrRobert Griesemer
authored andcommitted
all: use strings.ReplaceAll where applicable
``` find . \ -not -path './.git/*' \ -not -path './test/*' \ -not -path './src/cmd/vendor/*' \ -not -wholename './src/strings/example_test.go' \ -type f \ -exec \ sed -i -E 's/strings\.Replace\((.+), -1\)/strings\.ReplaceAll\(\1\)/g' {} \; ``` Change-Id: I59e2e91b3654c41a32f17dd91ec56f250198f0d6 GitHub-Last-Rev: 0868b1e GitHub-Pull-Request: #73370 Reviewed-on: https://go-review.googlesource.com/c/go/+/665395 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Keith Randall <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 2cb9e7f commit 5715d73

File tree

24 files changed

+54
-54
lines changed

24 files changed

+54
-54
lines changed

src/cmd/cgo/gcc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ func (c *typeConv) loadType(dtype dwarf.Type, pos token.Pos, parent string) *Typ
28632863
if ss, ok := dwarfToName[s]; ok {
28642864
s = ss
28652865
}
2866-
s = strings.Replace(s, " ", "", -1)
2866+
s = strings.ReplaceAll(s, " ", "")
28672867
name := c.Ident("_Ctype_" + s)
28682868
tt := *t
28692869
typedef[name.Name] = &tt

src/cmd/cgo/internal/testplugin/plugin_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ func goCmd(t *testing.T, op string, args ...string) string {
145145

146146
// escape converts a string to something suitable for a shell command line.
147147
func escape(s string) string {
148-
s = strings.Replace(s, "\\", "\\\\", -1)
149-
s = strings.Replace(s, "'", "\\'", -1)
148+
s = strings.ReplaceAll(s, "\\", "\\\\")
149+
s = strings.ReplaceAll(s, "'", "\\'")
150150
// Conservative guess at characters that will force quoting
151151
if s == "" || strings.ContainsAny(s, "\\ ;#*&$~?!|[]()<>{}`") {
152152
s = "'" + s + "'"

src/cmd/cgo/out.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ func (p *Package) writeDefs() {
251251
}
252252

253253
if callsMalloc && !*gccgo {
254-
fmt.Fprint(fgo2, strings.Replace(cMallocDefGo, "PREFIX", cPrefix, -1))
255-
fmt.Fprint(fgcc, strings.Replace(strings.Replace(cMallocDefC, "PREFIX", cPrefix, -1), "PACKED", p.packedAttribute(), -1))
254+
fmt.Fprint(fgo2, strings.ReplaceAll(cMallocDefGo, "PREFIX", cPrefix))
255+
fmt.Fprint(fgcc, strings.ReplaceAll(strings.Replace(cMallocDefC, "PREFIX", cPrefix, -1), "PACKED", p.packedAttribute()))
256256
}
257257

258258
if err := fgcc.Close(); err != nil {
@@ -1954,7 +1954,7 @@ extern const char *_GoStringPtr(_GoString_ s);
19541954
`
19551955

19561956
func (p *Package) gccExportHeaderProlog() string {
1957-
return strings.Replace(gccExportHeaderProlog, "GOINTBITS", fmt.Sprint(8*p.IntSize), -1)
1957+
return strings.ReplaceAll(gccExportHeaderProlog, "GOINTBITS", fmt.Sprint(8*p.IntSize))
19581958
}
19591959

19601960
// gccExportHeaderProlog is written to the exported header, after the

src/cmd/compile/internal/dwarfgen/scope_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func TestScopeRanges(t *testing.T) {
226226
defer f.Close()
227227

228228
// the compiler uses forward slashes for paths even on windows
229-
src = strings.Replace(src, "\\", "/", -1)
229+
src = strings.ReplaceAll(src, "\\", "/")
230230

231231
pcln, err := f.PCLineTable()
232232
if err != nil {

src/cmd/compile/internal/logopt/log_opts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ var mu = sync.Mutex{} // mu protects loggedOpts.
326326
// funcName is the name of the function
327327
// A typical use for this to accumulate an explanation for a missed optimization, for example, why did something escape?
328328
func NewLoggedOpt(pos, lastPos src.XPos, what, pass, funcName string, args ...interface{}) *LoggedOpt {
329-
pass = strings.Replace(pass, " ", "_", -1)
329+
pass = strings.ReplaceAll(pass, " ", "_")
330330
return &LoggedOpt{pos, lastPos, pass, funcName, what, args}
331331
}
332332

@@ -405,7 +405,7 @@ func fixSlash(f string) string {
405405
if os.PathSeparator == '/' {
406406
return f
407407
}
408-
return strings.Replace(f, string(os.PathSeparator), "/", -1)
408+
return strings.ReplaceAll(f, string(os.PathSeparator), "/")
409409
}
410410

411411
func uriIfy(f string) DocumentURI {

src/cmd/compile/internal/ssa/_gen/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func genOp() {
350350
if !needEffect {
351351
log.Fatalf("symEffect with aux %s not allowed", v.aux)
352352
}
353-
fmt.Fprintf(w, "symEffect: Sym%s,\n", strings.Replace(v.symEffect, ",", "|Sym", -1))
353+
fmt.Fprintf(w, "symEffect: Sym%s,\n", strings.ReplaceAll(v.symEffect, ",", "|Sym"))
354354
} else if needEffect {
355355
log.Fatalf("symEffect needed for aux %s", v.aux)
356356
}

src/cmd/compile/internal/ssa/_gen/rulegen.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,11 +1623,11 @@ func varCount1(loc, m string, cnt map[string]int) {
16231623
// normalizeWhitespace replaces 2+ whitespace sequences with a single space.
16241624
func normalizeWhitespace(x string) string {
16251625
x = strings.Join(strings.Fields(x), " ")
1626-
x = strings.Replace(x, "( ", "(", -1)
1627-
x = strings.Replace(x, " )", ")", -1)
1628-
x = strings.Replace(x, "[ ", "[", -1)
1629-
x = strings.Replace(x, " ]", "]", -1)
1630-
x = strings.Replace(x, ")=>", ") =>", -1)
1626+
x = strings.ReplaceAll(x, "( ", "(")
1627+
x = strings.ReplaceAll(x, " )", ")")
1628+
x = strings.ReplaceAll(x, "[ ", "[")
1629+
x = strings.ReplaceAll(x, " ]", "]")
1630+
x = strings.ReplaceAll(x, ")=>", ") =>")
16311631
return x
16321632
}
16331633

src/cmd/compile/internal/ssa/compile.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,9 @@ func Compile(f *Func) {
169169
func (f *Func) DumpFileForPhase(phaseName string) io.WriteCloser {
170170
f.dumpFileSeq++
171171
fname := fmt.Sprintf("%s_%02d__%s.dump", f.Name, int(f.dumpFileSeq), phaseName)
172-
fname = strings.Replace(fname, " ", "_", -1)
173-
fname = strings.Replace(fname, "/", "_", -1)
174-
fname = strings.Replace(fname, ":", "_", -1)
172+
fname = strings.ReplaceAll(fname, " ", "_")
173+
fname = strings.ReplaceAll(fname, "/", "_")
174+
fname = strings.ReplaceAll(fname, ":", "_")
175175

176176
if ssaDir := os.Getenv("GOSSADIR"); ssaDir != "" {
177177
fname = filepath.Join(ssaDir, fname)
@@ -264,7 +264,7 @@ func PhaseOption(phase, flag string, val int, valString string) string {
264264
lastcr := 0
265265
phasenames := " check, all, build, intrinsics, genssa"
266266
for _, p := range passes {
267-
pn := strings.Replace(p.name, " ", "_", -1)
267+
pn := strings.ReplaceAll(p.name, " ", "_")
268268
if len(pn)+len(phasenames)-lastcr > 70 {
269269
phasenames += "\n "
270270
lastcr = len(phasenames)
@@ -400,7 +400,7 @@ commas. For example:
400400
return ""
401401
}
402402

403-
underphase := strings.Replace(phase, "_", " ", -1)
403+
underphase := strings.ReplaceAll(phase, "_", " ")
404404
var re *regexp.Regexp
405405
if phase[0] == '~' {
406406
r, ok := regexp.Compile(underphase[1:])

src/cmd/compile/internal/ssa/debug_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ func printVariableAndNormalize(v string, printer func(v string) string) string {
694694
if dollar == -1 { // some not entirely expected response, whine and carry on.
695695
if cr == -1 {
696696
response = strings.TrimSpace(response) // discards trailing newline
697-
response = strings.Replace(response, "\n", "<BR>", -1)
697+
response = strings.ReplaceAll(response, "\n", "<BR>")
698698
return "$ Malformed response " + response
699699
}
700700
response = strings.TrimSpace(response[:cr])
@@ -986,8 +986,8 @@ func asCommandLine(cwd string, cmd *exec.Cmd) string {
986986

987987
// escape inserts escapes appropriate for use in a shell command line
988988
func escape(s string) string {
989-
s = strings.Replace(s, "\\", "\\\\", -1)
990-
s = strings.Replace(s, "'", "\\'", -1)
989+
s = strings.ReplaceAll(s, "\\", "\\\\")
990+
s = strings.ReplaceAll(s, "'", "\\'")
991991
// Conservative guess at characters that will force quoting
992992
if strings.ContainsAny(s, "\\ ;#*&$~?!|[]()<>{}`") {
993993
s = " '" + s + "'"

src/cmd/compile/internal/ssa/func.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func (f *Func) LogStat(key string, args ...interface{}) {
342342
}
343343
n := "missing_pass"
344344
if f.pass != nil {
345-
n = strings.Replace(f.pass.name, " ", "_", -1)
345+
n = strings.ReplaceAll(f.pass.name, " ", "_")
346346
}
347347
f.Warnl(f.Entry.Pos, "\t%s\t%s%s\t%s", n, key, value, f.Name)
348348
}

0 commit comments

Comments
 (0)