Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: replace strings.Replace with string.ReplaceAll #24835

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ethstats/ethstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions internal/debug/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions les/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion metrics/prometheus/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/", "_")
}
2 changes: 1 addition & 1 deletion p2p/nat/natupnp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion rlp/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down