Skip to content

Commit 0b296d0

Browse files
use strings.ReplaceAll instead of Replace with -1
1 parent 522f2f1 commit 0b296d0

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

arduino/builder/cpp/cpp.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
// preprocessor. This adds double quotes around it and escapes any
2828
// double quotes and backslashes in the string.
2929
func QuoteString(str string) string {
30-
str = strings.Replace(str, "\\", "\\\\", -1)
31-
str = strings.Replace(str, "\"", "\\\"", -1)
30+
str = strings.ReplaceAll(str, "\\", "\\\\")
31+
str = strings.ReplaceAll(str, "\"", "\\\"")
3232
return "\"" + str + "\""
3333
}
3434

arduino/builder/preprocessor/ctags.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func PreprocessSketchWithCtags(sketch *sketch.Sketch, buildPath *paths.Path, inc
103103
} else {
104104
return normalOutput.Bytes(), verboseOutput.Bytes(), err
105105
}
106-
source = strings.Replace(source, "\r\n", "\n", -1)
107-
source = strings.Replace(source, "\r", "\n", -1)
106+
source = strings.ReplaceAll(source, "\r\n", "\n")
107+
source = strings.ReplaceAll(source, "\r", "\n")
108108
sourceRows := strings.Split(source, "\n")
109109
if isFirstFunctionOutsideOfSource(firstFunctionLine, sourceRows) {
110110
return normalOutput.Bytes(), verboseOutput.Bytes(), nil

arduino/builder/preprocessor/internal/ctags/ctags_parser.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func removeTralingSemicolon(s string) string {
167167
}
168168

169169
func removeSpacesAndTabs(s string) string {
170-
s = strings.Replace(s, " ", "", -1)
171-
s = strings.Replace(s, "\t", "", -1)
170+
s = strings.ReplaceAll(s, " ", "")
171+
s = strings.ReplaceAll(s, "\t", "")
172172
return s
173173
}
174174

@@ -205,7 +205,7 @@ func parseTag(row string) *Tag {
205205
// and just cuts off the filename at the first double quote it
206206
// sees. This means any backslashes are still escaped, and need
207207
// to be unescape, and any quotes will just break the build.
208-
tag.Filename = strings.Replace(parts[1], "\\\\", "\\", -1)
208+
tag.Filename = strings.ReplaceAll(parts[1], "\\\\", "\\")
209209

210210
parts = parts[2:]
211211

commands/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
310310
exportPath = paths.New(exportDir)
311311
} else {
312312
// Add FQBN (without configs part) to export path
313-
fqbnSuffix := strings.Replace(fqbn.StringWithoutConfig(), ":", ".", -1)
313+
fqbnSuffix := strings.ReplaceAll(fqbn.StringWithoutConfig(), ":", ".")
314314
exportPath = sk.FullPath.Join("build", fqbnSuffix)
315315
}
316316
logrus.WithField("path", exportPath).Trace("Saving sketch to export path.")

i18n/convert.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ func FromJavaToGoSyntax(s string) string {
3434
if err != nil {
3535
panic(err)
3636
}
37-
s = strings.Replace(s, submatch[0], "%["+strconv.Itoa(idx+1)+"]v", -1)
37+
s = strings.ReplaceAll(s, submatch[0], "%["+strconv.Itoa(idx+1)+"]v")
3838
}
3939

4040
// Replace "''" => "'"
41-
s = strings.Replace(s, "''", "'", -1)
41+
s = strings.ReplaceAll(s, "''", "'")
4242

4343
return s
4444
}

internal/cli/lib/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (res result) String() string {
163163
out.WriteString(fmt.Sprintf(" "+tr("Category: %s")+"\n", latest.Category))
164164
out.WriteString(fmt.Sprintf(" "+tr("Architecture: %s")+"\n", strings.Join(latest.Architectures, ", ")))
165165
out.WriteString(fmt.Sprintf(" "+tr("Types: %s")+"\n", strings.Join(latest.Types, ", ")))
166-
out.WriteString(fmt.Sprintf(" "+tr("Versions: %s")+"\n", strings.Replace(fmt.Sprint(lib.GetAvailableVersions()), " ", ", ", -1)))
166+
out.WriteString(fmt.Sprintf(" "+tr("Versions: %s")+"\n", strings.ReplaceAll(fmt.Sprint(lib.GetAvailableVersions()), " ", ", ")))
167167
if len(latest.ProvidesIncludes) > 0 {
168168
out.WriteString(fmt.Sprintf(" "+tr("Provides includes: %s")+"\n", strings.Join(latest.ProvidesIncludes, ", ")))
169169
}

internal/integrationtest/compile_4/compile_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ func comparePreprocessGoldenFile(t *testing.T, sketchDir *paths.Path, preprocess
904904
err = tpl.Execute(&buf, data)
905905
require.NoError(t, err)
906906

907-
require.Equal(t, buf.String(), strings.Replace(preprocessedSketch, "\r\n", "\n", -1))
907+
require.Equal(t, buf.String(), strings.ReplaceAll(preprocessedSketch, "\r\n", "\n"))
908908
}
909909

910910
func TestCoreCaching(t *testing.T) {

0 commit comments

Comments
 (0)