all: Simplify some method calls (#7499)

strings.Replace(a, b, c, -1) -> strings.ReplaceAll(a, b, c)

(Go 1.12) and who knows what was up with that dialQueue.Sort() thing.
This commit is contained in:
Jakob Borg 2021-03-17 23:12:26 +01:00 committed by GitHub
parent 960e850a78
commit 8ef504f745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 18 additions and 19 deletions

View File

@ -37,7 +37,7 @@ type result struct {
func main() {
flag.Parse()
prefix := strings.ToUpper(strings.Replace(flag.Arg(0), "-", "", -1))
prefix := strings.ToUpper(strings.ReplaceAll(flag.Arg(0), "-", ""))
if len(prefix) > 7 {
prefix = prefix[:7] + "-" + prefix[7:]
}

View File

@ -725,8 +725,8 @@ func getReport(db *sql.DB) map[string]interface{} {
if rep.NATType != "" {
natType := rep.NATType
natType = strings.Replace(natType, "unknown", "Unknown", -1)
natType = strings.Replace(natType, "Symetric", "Symmetric", -1)
natType = strings.ReplaceAll(natType, "unknown", "Unknown")
natType = strings.ReplaceAll(natType, "Symetric", "Symmetric")
add(featureGroups["Various"]["v3"], "NAT Type", natType, 1)
}

View File

@ -79,7 +79,7 @@ func (t *quicListener) OnExternalAddressChanged(address *stun.Host, via string)
}
func (t *quicListener) serve(ctx context.Context) error {
network := strings.Replace(t.uri.Scheme, "quic", "udp", -1)
network := strings.ReplaceAll(t.uri.Scheme, "quic", "udp")
packetConn, err := net.ListenPacket(network, t.uri.Host)
if err != nil {
@ -174,7 +174,7 @@ func (t *quicListener) WANAddresses() []*url.URL {
func (t *quicListener) LANAddresses() []*url.URL {
addrs := []*url.URL{t.uri}
network := strings.Replace(t.uri.Scheme, "quic", "udp", -1)
network := strings.ReplaceAll(t.uri.Scheme, "quic", "udp")
addrs = append(addrs, getURLsForAllAdaptersIfUnspecified(network, t.uri)...)
return addrs
}

View File

@ -478,7 +478,7 @@ func (s *service) dialDevices(ctx context.Context, now time.Time, cfg config.Con
// doesn't have much effect, but it may result in getting up and running
// quicker if only a subset of configured devices are actually reachable
// (by prioritizing those that were reachable recently).
dialQueue.Sort(queue)
queue.Sort()
// Perform dials according to the queue, stopping when we've reached the
// allowed additional number of connections (if limited).

View File

@ -252,8 +252,7 @@ func Canonicalize(file string) (string, error) {
file = filepath.Clean(file)
// It is not acceptable to attempt to traverse upwards.
switch file {
case "..":
if file == ".." {
return "", errNotRelative
}
if strings.HasPrefix(file, ".."+pathSep) {

View File

@ -115,7 +115,7 @@ func expandLocations() error {
newLocations := make(map[LocationEnum]string)
for key, dir := range locationTemplates {
for varName, value := range baseDirs {
dir = strings.Replace(dir, "${"+string(varName)+"}", value, -1)
dir = strings.ReplaceAll(dir, "${"+string(varName)+"}", value)
}
var err error
dir, err = fs.ExpandTilde(dir)
@ -197,5 +197,5 @@ func GetTimestamped(key LocationEnum) string {
// 2006 replaced by 2015...
tpl := locations[key]
now := time.Now().Format("20060102-150405")
return strings.Replace(tpl, "${timestamp}", now, -1)
return strings.ReplaceAll(tpl, "${timestamp}", now)
}

View File

@ -692,7 +692,7 @@ func (m *model) UsageReportingStats(report *contract.Report, version int, previe
if strings.Contains(line, "**") {
report.IgnoreStats.DoubleStars++
// Remove not to trip up star checks.
line = strings.Replace(line, "**", "", -1)
line = strings.ReplaceAll(line, "**", "")
}
if strings.Contains(line, "*") {

View File

@ -203,15 +203,15 @@ func chunkify(s string) string {
}
func unchunkify(s string) string {
s = strings.Replace(s, "-", "", -1)
s = strings.Replace(s, " ", "", -1)
s = strings.ReplaceAll(s, "-", "")
s = strings.ReplaceAll(s, " ", "")
return s
}
func untypeoify(s string) string {
s = strings.Replace(s, "0", "O", -1)
s = strings.Replace(s, "1", "I", -1)
s = strings.Replace(s, "8", "B", -1)
s = strings.ReplaceAll(s, "0", "O")
s = strings.ReplaceAll(s, "1", "I")
s = strings.ReplaceAll(s, "8", "B")
return s
}

View File

@ -156,7 +156,7 @@ USER-AGENT: syncthing/1.0
`
searchStr := fmt.Sprintf(tpl, deviceType, timeout/time.Second)
search := []byte(strings.Replace(searchStr, "\n", "\r\n", -1) + "\r\n")
search := []byte(strings.ReplaceAll(searchStr, "\n", "\r\n") + "\r\n")
l.Debugln("Starting discovery of device type", deviceType, "on", intf.Name)

View File

@ -36,7 +36,7 @@ func newExternal(cfg config.FolderConfiguration) Versioner {
command := cfg.Versioning.Params["command"]
if runtime.GOOS == "windows" {
command = strings.Replace(command, `\`, `\\`, -1)
command = strings.ReplaceAll(command, `\`, `\\`)
}
s := external{
@ -81,7 +81,7 @@ func (v external) Archive(filePath string) error {
for i, word := range words {
for key, val := range context {
word = strings.Replace(word, key, val, -1)
word = strings.ReplaceAll(word, key, val)
}
words[i] = word