From 7caa2d8163ae3132c1c2d6978c76610caee2d949 Mon Sep 17 00:00:00 2001 From: s7v7nislands Date: Mon, 9 May 2022 18:13:23 +0800 Subject: [PATCH] all: replace strings.Replace with string.ReplaceAll (#24835) --- accounts/abi/bind/bind.go | 2 +- accounts/abi/bind/template.go | 2 +- accounts/abi/type.go | 2 +- eth/downloader/downloader_test.go | 4 ++-- ethstats/ethstats.go | 2 +- internal/debug/api.go | 4 ++-- les/downloader/downloader_test.go | 4 ++-- metrics/prometheus/collector.go | 2 +- p2p/nat/natupnp_test.go | 2 +- rlp/decode_test.go | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go index ff69a78c64..2bd8b6dde0 100644 --- a/accounts/abi/bind/bind.go +++ b/accounts/abi/bind/bind.go @@ -179,7 +179,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string] contracts[types[i]] = &tmplContract{ Type: capitalise(types[i]), - InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1), + InputABI: strings.ReplaceAll(strippedABI, "\"", "\\\""), InputBin: strings.TrimPrefix(strings.TrimSpace(bytecodes[i]), "0x"), Constructor: evmABI.Constructor, Calls: calls, diff --git a/accounts/abi/bind/template.go b/accounts/abi/bind/template.go index 492bad8c57..c9b001133d 100644 --- a/accounts/abi/bind/template.go +++ b/accounts/abi/bind/template.go @@ -161,7 +161,7 @@ var ( } {{range $pattern, $name := .Libraries}} {{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend) - {{$contract.Type}}Bin = strings.Replace({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:], -1) + {{$contract.Type}}Bin = strings.ReplaceAll({{$contract.Type}}Bin, "__${{$pattern}}$__", {{decapitalise $name}}Addr.String()[2:]) {{end}} address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}}) if err != nil { diff --git a/accounts/abi/type.go b/accounts/abi/type.go index ffa3acafe9..0ca208b08b 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -201,7 +201,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty if internalType != "" && strings.HasPrefix(internalType, structPrefix) { // Foo.Bar type definition is not allowed in golang, // convert the format to FooBar - typ.TupleRawName = strings.Replace(internalType[len(structPrefix):], ".", "", -1) + typ.TupleRawName = strings.ReplaceAll(internalType[len(structPrefix):], ".", "") } case "function": diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index 78380c2e8d..a5db037a45 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -1331,8 +1331,8 @@ func TestRemoteHeaderRequestSpan(t *testing.T) { } } if failed { - res := strings.Replace(fmt.Sprint(data), " ", ",", -1) - exp := strings.Replace(fmt.Sprint(tt.expected), " ", ",", -1) + res := strings.ReplaceAll(fmt.Sprint(data), " ", ",") + exp := strings.ReplaceAll(fmt.Sprint(tt.expected), " ", ",") t.Logf("got: %v\n", res) t.Logf("exp: %v\n", exp) t.Errorf("test %d: wrong values", i) diff --git a/ethstats/ethstats.go b/ethstats/ethstats.go index 55c0c880f3..5d60efab2e 100644 --- a/ethstats/ethstats.go +++ b/ethstats/ethstats.go @@ -366,7 +366,7 @@ func (s *Service) readLoop(conn *connWrapper) { // If the network packet is a system ping, respond to it directly var ping string if err := json.Unmarshal(blob, &ping); err == nil && strings.HasPrefix(ping, "primus::ping::") { - if err := conn.WriteJSON(strings.Replace(ping, "ping", "pong", -1)); err != nil { + if err := conn.WriteJSON(strings.ReplaceAll(ping, "ping", "pong")); err != nil { log.Warn("Failed to respond to system ping message", "err", err) return } diff --git a/internal/debug/api.go b/internal/debug/api.go index 1ea0c6377f..42d0fa15ed 100644 --- a/internal/debug/api.go +++ b/internal/debug/api.go @@ -209,8 +209,8 @@ func (*HandlerT) Stacks(filter *string) string { // E.g. (eth || snap) && !p2p -> (eth in Value || snap in Value) && p2p not in Value expanded = regexp.MustCompile(`[:/\.A-Za-z0-9_-]+`).ReplaceAllString(expanded, "`$0` in Value") expanded = regexp.MustCompile("!(`[:/\\.A-Za-z0-9_-]+`)").ReplaceAllString(expanded, "$1 not") - expanded = strings.Replace(expanded, "||", "or", -1) - expanded = strings.Replace(expanded, "&&", "and", -1) + expanded = strings.ReplaceAll(expanded, "||", "or") + expanded = strings.ReplaceAll(expanded, "&&", "and") log.Info("Expanded filter expression", "filter", *filter, "expanded", expanded) expr, err := bexpr.CreateEvaluator(expanded) diff --git a/les/downloader/downloader_test.go b/les/downloader/downloader_test.go index 69bdb90ed2..f6510eb412 100644 --- a/les/downloader/downloader_test.go +++ b/les/downloader/downloader_test.go @@ -1577,8 +1577,8 @@ func TestRemoteHeaderRequestSpan(t *testing.T) { } } if failed { - res := strings.Replace(fmt.Sprint(data), " ", ",", -1) - exp := strings.Replace(fmt.Sprint(tt.expected), " ", ",", -1) + res := strings.ReplaceAll(fmt.Sprint(data), " ", ",") + exp := strings.ReplaceAll(fmt.Sprint(tt.expected), " ", ",") t.Logf("got: %v\n", res) t.Logf("exp: %v\n", exp) t.Errorf("test %d: wrong values", i) diff --git a/metrics/prometheus/collector.go b/metrics/prometheus/collector.go index 3959cbf5e1..e8d5e4f5d1 100644 --- a/metrics/prometheus/collector.go +++ b/metrics/prometheus/collector.go @@ -116,5 +116,5 @@ func (c *collector) writeSummaryPercentile(name, p string, value interface{}) { } func mutateKey(key string) string { - return strings.Replace(key, "/", "_", -1) + return strings.ReplaceAll(key, "/", "_") } diff --git a/p2p/nat/natupnp_test.go b/p2p/nat/natupnp_test.go index 17483a7036..9072451d50 100644 --- a/p2p/nat/natupnp_test.go +++ b/p2p/nat/natupnp_test.go @@ -223,7 +223,7 @@ func (dev *fakeIGD) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func (dev *fakeIGD) replaceListenAddr(resp string) string { - return strings.Replace(resp, "{{listenAddr}}", dev.listener.Addr().String(), -1) + return strings.ReplaceAll(resp, "{{listenAddr}}", dev.listener.Addr().String()) } func (dev *fakeIGD) listen() (err error) { diff --git a/rlp/decode_test.go b/rlp/decode_test.go index babdf3891b..46aa68cea3 100644 --- a/rlp/decode_test.go +++ b/rlp/decode_test.go @@ -1203,7 +1203,7 @@ func encodeTestSlice(n uint) []byte { } func unhex(str string) []byte { - b, err := hex.DecodeString(strings.Replace(str, " ", "", -1)) + b, err := hex.DecodeString(strings.ReplaceAll(str, " ", "")) if err != nil { panic(fmt.Sprintf("invalid hex string: %q", str)) }