diff --git a/kobopatch/kobopatch.go b/kobopatch/kobopatch.go index b88e925..a15f0e8 100644 --- a/kobopatch/kobopatch.go +++ b/kobopatch/kobopatch.go @@ -63,7 +63,7 @@ func main() { } patchfile.Log = func(format string, a ...interface{}) { - k.Debugf(" | %s", strings.Replace(fmt.Sprintf(strings.TrimRight(format, "\n"), a...), "\n", "\n | ", -1)) + k.Debugf(" | %s", strings.ReplaceAll(fmt.Sprintf(strings.TrimRight(format, "\n"), a...), "\n", "\n | ")) } k.Logf("kobopatch %s\nhttps://github.com/geek1011/kobopatch\n", version) @@ -793,7 +793,7 @@ func (k *KoboPatch) d(format string, a ...interface{}) { } func (k *KoboPatch) dp(prefix string, format string, a ...interface{}) { - k.d("%s%s", prefix, strings.Replace(fmt.Sprintf(format, a...), "\n", "\n"+prefix, -1)) + k.d("%s%s", prefix, strings.ReplaceAll(fmt.Sprintf(format, a...), "\n", "\n"+prefix)) } func wrap(err error, format string, a ...interface{}) error { @@ -809,8 +809,8 @@ func jm(v interface{}) string { func getFormat(filename string) string { f := strings.TrimLeft(filepath.Ext(filename), ".") - f = strings.Replace(f, "patch", "patch32lsb", -1) - f = strings.Replace(f, "yaml", "kobopatch", -1) + f = strings.ReplaceAll(f, "patch", "patch32lsb") + f = strings.ReplaceAll(f, "yaml", "kobopatch") return f } diff --git a/patchfile/kobopatch/patch.go b/patchfile/kobopatch/patch.go index 34c6243..9d67f9b 100644 --- a/patchfile/kobopatch/patch.go +++ b/patchfile/kobopatch/patch.go @@ -118,7 +118,7 @@ func (b BaseAddress) ApplyTo(pt *patchlib.Patcher, log func(string, ...interface func (b FindBaseAddressHex) ApplyTo(pt *patchlib.Patcher, log func(string, ...interface{})) error { log("FindBaseAddressHex(%#v)", b) var buf []byte - _, err := fmt.Sscanf(strings.Replace(string(b), " ", "", -1), "%x\n", &buf) + _, err := fmt.Sscanf(strings.ReplaceAll(string(b), " ", ""), "%x\n", &buf) if err != nil { return errors.Wrap(err, "FindBaseAddressHex: error parsing hex") } @@ -328,6 +328,6 @@ func expandHex(in *string, out *[]byte) (bool, error) { if in == nil { return false, nil } - _, err := fmt.Sscanf(strings.Replace(*in, " ", "", -1), "%x\n", out) + _, err := fmt.Sscanf(strings.ReplaceAll(*in, " ", ""), "%x\n", out) return true, errors.Wrapf(err, "error expanding shorthand hex `%s`", *in) } diff --git a/patchfile/patch32lsb/patch32lsb.go b/patchfile/patch32lsb/patch32lsb.go index a46fef1..0b6d9a3 100644 --- a/patchfile/patch32lsb/patch32lsb.go +++ b/patchfile/patch32lsb/patch32lsb.go @@ -65,7 +65,7 @@ func Parse(buf []byte) (patchfile.PatchSet, error) { var inPatch bool curPatch := patch{} eqRegexp := regexp.MustCompile(" +?= +?") - for i, l := range strings.Split(strings.Replace(string(buf), "\r\n", "\n", -1), "\n") { + for i, l := range strings.Split(strings.ReplaceAll(string(buf), "\r\n", "\n"), "\n") { l = strings.TrimSpace(l) switch { case strings.HasPrefix(l, "#"), l == "": @@ -127,7 +127,7 @@ func Parse(buf []byte) (patchfile.PatchSet, error) { return nil, errors.Errorf("line %d: unexpected patch_enable value '%s' (should be yes or no)", i+1, spl[1]) } case "replace_bytes": - args := strings.Replace(spl[1], " ", "", -1) + args := strings.ReplaceAll(spl[1], " ", "") var offset int32 var find, replace []byte _, err := fmt.Sscanf(args, "%x,%x,%x", &offset, &find, &replace) @@ -147,7 +147,7 @@ func Parse(buf []byte) (patchfile.PatchSet, error) { } curPatch = append(curPatch, instruction{BaseAddress: &addr}) case "replace_float": - args := strings.Replace(spl[1], " ", "", -1) + args := strings.ReplaceAll(spl[1], " ", "") var offset int32 var find, replace float64 _, err := fmt.Sscanf(args, "%x,%f,%f", &offset, &find, &replace) @@ -160,7 +160,7 @@ func Parse(buf []byte) (patchfile.PatchSet, error) { Replace float64 }{Offset: offset, Find: find, Replace: replace}}) case "replace_int": - args := strings.Replace(spl[1], " ", "", -1) + args := strings.ReplaceAll(spl[1], " ", "") var offset int32 var find, replace uint8 _, err := fmt.Sscanf(args, "%x,%d,%d", &offset, &find, &replace) diff --git a/patchlib/patcher.go b/patchlib/patcher.go index 676f8fb..ce9a77c 100644 --- a/patchlib/patcher.go +++ b/patchlib/patcher.go @@ -135,12 +135,12 @@ func (p *Patcher) FindZlib(find string) error { continue } // Handle minification from below - zi.CSS = strings.Replace(zi.CSS, "\n ", "\n", -1) - zi.CSS = strings.Replace(zi.CSS, "\n ", "\n", -1) - zi.CSS = strings.Replace(zi.CSS, "\n ", "\n", -1) - findm := strings.Replace(find, "\n ", "\n", -1) - findm = strings.Replace(find, "\n ", "\n", -1) - findm = strings.Replace(findm, "\n ", "\n", -1) + zi.CSS = strings.ReplaceAll(zi.CSS, "\n ", "\n") + zi.CSS = strings.ReplaceAll(zi.CSS, "\n ", "\n") + zi.CSS = strings.ReplaceAll(zi.CSS, "\n ", "\n") + findm := strings.ReplaceAll(find, "\n ", "\n") + findm = strings.ReplaceAll(find, "\n ", "\n") + findm = strings.ReplaceAll(findm, "\n ", "\n") if strings.Contains(zi.CSS, findm) || strings.Contains(stripWhitespace(zi.CSS), stripWhitespace(findm)) { if i != 0 { return errors.New("FindZlib: substring to find is not unique") @@ -148,10 +148,10 @@ func (p *Patcher) FindZlib(find string) error { i = zi.Offset continue } - zi.CSS = strings.Replace(zi.CSS, ": ", ":", -1) - zi.CSS = strings.Replace(zi.CSS, " {", "{", -1) - findm = strings.Replace(findm, ": ", ":", -1) - findm = strings.Replace(findm, " {", "{", -1) + zi.CSS = strings.ReplaceAll(zi.CSS, ": ", ":") + zi.CSS = strings.ReplaceAll(zi.CSS, " {", "{") + findm = strings.ReplaceAll(findm, ": ", ":") + findm = strings.ReplaceAll(findm, " {", "{") if strings.Contains(zi.CSS, findm) || strings.Contains(stripWhitespace(zi.CSS), stripWhitespace(findm)) { if i != 0 { return errors.New("FindZlib: substring to find is not unique") @@ -159,11 +159,11 @@ func (p *Patcher) FindZlib(find string) error { i = zi.Offset continue } - zi.CSS = strings.Replace(zi.CSS, "\n", "", -1) - zi.CSS = strings.Replace(zi.CSS, "{ ", "", -1) - zi.CSS = strings.Replace(zi.CSS, "; ", "", -1) - findm = strings.Replace(findm, "{ ", "{", -1) - findm = strings.Replace(findm, "; ", ";", -1) + zi.CSS = strings.ReplaceAll(zi.CSS, "\n", "") + zi.CSS = strings.ReplaceAll(zi.CSS, "{ ", "") + zi.CSS = strings.ReplaceAll(zi.CSS, "; ", "") + findm = strings.ReplaceAll(findm, "{ ", "{") + findm = strings.ReplaceAll(findm, "; ", ";") if strings.Contains(zi.CSS, findm) || strings.Contains(stripWhitespace(zi.CSS), stripWhitespace(findm)) { if i != 0 { return errors.New("FindZlib: substring to find is not unique") @@ -236,18 +236,18 @@ func (p *Patcher) ReplaceZlibGroup(offset int32, repl []Replacement) error { for _, r := range repl { find, replace := r.Find, r.Replace if !bytes.Contains(dbuf, []byte(find)) { - find = strings.Replace(find, "\n ", "\n", -1) - find = strings.Replace(find, "\n ", "\n", -1) - find = strings.Replace(find, "\n ", "\n", -1) + find = strings.ReplaceAll(find, "\n ", "\n") + find = strings.ReplaceAll(find, "\n ", "\n") + find = strings.ReplaceAll(find, "\n ", "\n") if !bytes.Contains(dbuf, []byte(find)) { - find = strings.Replace(find, ": ", ":", -1) - find = strings.Replace(find, " {", "{", -1) + find = strings.ReplaceAll(find, ": ", ":") + find = strings.ReplaceAll(find, " {", "{") if !bytes.Contains(dbuf, []byte(find)) { - find = strings.Replace(find, "\n", "", -1) - find = strings.Replace(find, "; ", ";", -1) - find = strings.Replace(find, "{ ", "{", -1) + find = strings.ReplaceAll(find, "\n", "") + find = strings.ReplaceAll(find, "; ", ";") + find = strings.ReplaceAll(find, "{ ", "{") if !bytes.Contains(dbuf, []byte(find)) { - return errors.Errorf("ReplaceZlib: find string not found in stream (%s)", strings.Replace(find, "\n", "\\n", -1)) + return errors.Errorf("ReplaceZlib: find string not found in stream (%s)", strings.ReplaceAll(find, "\n", "\\n")) } } } @@ -471,9 +471,9 @@ func decompress(src []byte) ([]byte, error) { } func stripWhitespace(src string) string { - src = strings.Replace(src, " ", "", -1) - src = strings.Replace(src, "\t", "", -1) - src = strings.Replace(src, "\n", "", -1) - src = strings.Replace(src, "\r", "", -1) + src = strings.ReplaceAll(src, " ", "") + src = strings.ReplaceAll(src, "\t", "") + src = strings.ReplaceAll(src, "\n", "") + src = strings.ReplaceAll(src, "\r", "") return src }