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

This commit is contained in:
s7v7nislands 2022-05-09 18:13:23 +08:00 committed by GitHub
parent 86d5477079
commit 7caa2d8163
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 13 additions and 13 deletions

@ -179,7 +179,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
contracts[types[i]] = &tmplContract{ contracts[types[i]] = &tmplContract{
Type: capitalise(types[i]), Type: capitalise(types[i]),
InputABI: strings.Replace(strippedABI, "\"", "\\\"", -1), InputABI: strings.ReplaceAll(strippedABI, "\"", "\\\""),
InputBin: strings.TrimPrefix(strings.TrimSpace(bytecodes[i]), "0x"), InputBin: strings.TrimPrefix(strings.TrimSpace(bytecodes[i]), "0x"),
Constructor: evmABI.Constructor, Constructor: evmABI.Constructor,
Calls: calls, Calls: calls,

@ -161,7 +161,7 @@ var (
} }
{{range $pattern, $name := .Libraries}} {{range $pattern, $name := .Libraries}}
{{decapitalise $name}}Addr, _, _, _ := Deploy{{capitalise $name}}(auth, backend) {{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}} {{end}}
address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}}) address, tx, contract, err := bind.DeployContract(auth, *parsed, common.FromHex({{.Type}}Bin), backend {{range .Constructor.Inputs}}, {{.Name}}{{end}})
if err != nil { if err != nil {

@ -201,7 +201,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
if internalType != "" && strings.HasPrefix(internalType, structPrefix) { if internalType != "" && strings.HasPrefix(internalType, structPrefix) {
// Foo.Bar type definition is not allowed in golang, // Foo.Bar type definition is not allowed in golang,
// convert the format to FooBar // convert the format to FooBar
typ.TupleRawName = strings.Replace(internalType[len(structPrefix):], ".", "", -1) typ.TupleRawName = strings.ReplaceAll(internalType[len(structPrefix):], ".", "")
} }
case "function": case "function":

@ -1331,8 +1331,8 @@ func TestRemoteHeaderRequestSpan(t *testing.T) {
} }
} }
if failed { if failed {
res := strings.Replace(fmt.Sprint(data), " ", ",", -1) res := strings.ReplaceAll(fmt.Sprint(data), " ", ",")
exp := strings.Replace(fmt.Sprint(tt.expected), " ", ",", -1) exp := strings.ReplaceAll(fmt.Sprint(tt.expected), " ", ",")
t.Logf("got: %v\n", res) t.Logf("got: %v\n", res)
t.Logf("exp: %v\n", exp) t.Logf("exp: %v\n", exp)
t.Errorf("test %d: wrong values", i) t.Errorf("test %d: wrong values", i)

@ -366,7 +366,7 @@ func (s *Service) readLoop(conn *connWrapper) {
// If the network packet is a system ping, respond to it directly // If the network packet is a system ping, respond to it directly
var ping string var ping string
if err := json.Unmarshal(blob, &ping); err == nil && strings.HasPrefix(ping, "primus::ping::") { 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) log.Warn("Failed to respond to system ping message", "err", err)
return return
} }

@ -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 // 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, "`$0` in Value")
expanded = regexp.MustCompile("!(`[:/\\.A-Za-z0-9_-]+`)").ReplaceAllString(expanded, "$1 not") expanded = regexp.MustCompile("!(`[:/\\.A-Za-z0-9_-]+`)").ReplaceAllString(expanded, "$1 not")
expanded = strings.Replace(expanded, "||", "or", -1) expanded = strings.ReplaceAll(expanded, "||", "or")
expanded = strings.Replace(expanded, "&&", "and", -1) expanded = strings.ReplaceAll(expanded, "&&", "and")
log.Info("Expanded filter expression", "filter", *filter, "expanded", expanded) log.Info("Expanded filter expression", "filter", *filter, "expanded", expanded)
expr, err := bexpr.CreateEvaluator(expanded) expr, err := bexpr.CreateEvaluator(expanded)

@ -1577,8 +1577,8 @@ func TestRemoteHeaderRequestSpan(t *testing.T) {
} }
} }
if failed { if failed {
res := strings.Replace(fmt.Sprint(data), " ", ",", -1) res := strings.ReplaceAll(fmt.Sprint(data), " ", ",")
exp := strings.Replace(fmt.Sprint(tt.expected), " ", ",", -1) exp := strings.ReplaceAll(fmt.Sprint(tt.expected), " ", ",")
t.Logf("got: %v\n", res) t.Logf("got: %v\n", res)
t.Logf("exp: %v\n", exp) t.Logf("exp: %v\n", exp)
t.Errorf("test %d: wrong values", i) t.Errorf("test %d: wrong values", i)

@ -116,5 +116,5 @@ func (c *collector) writeSummaryPercentile(name, p string, value interface{}) {
} }
func mutateKey(key string) string { func mutateKey(key string) string {
return strings.Replace(key, "/", "_", -1) return strings.ReplaceAll(key, "/", "_")
} }

@ -223,7 +223,7 @@ func (dev *fakeIGD) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
func (dev *fakeIGD) replaceListenAddr(resp string) string { 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) { func (dev *fakeIGD) listen() (err error) {

@ -1203,7 +1203,7 @@ func encodeTestSlice(n uint) []byte {
} }
func unhex(str string) []byte { func unhex(str string) []byte {
b, err := hex.DecodeString(strings.Replace(str, " ", "", -1)) b, err := hex.DecodeString(strings.ReplaceAll(str, " ", ""))
if err != nil { if err != nil {
panic(fmt.Sprintf("invalid hex string: %q", str)) panic(fmt.Sprintf("invalid hex string: %q", str))
} }