Skip to content

Commit

Permalink
refactor: use slices.Clone and slices.Replace
Browse files Browse the repository at this point in the history
  • Loading branch information
j178 committed Jan 4, 2024
1 parent 1061abf commit 0fe9195
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 3 additions & 3 deletions editor/editor.go
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"slices"
"strings"
"text/template"

Expand Down Expand Up @@ -72,8 +73,7 @@ func (ed *editor) substituteArgs(result *lang.GenerateResult) ([]string, error)
TestCasesFile: getPath(lang.TestCasesFile),
}

args := make([]string, len(ed.args))
copy(args, ed.args)
args := slices.Clone(ed.args)
for i, arg := range args {
if !strings.Contains(arg, "{{") {
continue
Expand All @@ -99,7 +99,7 @@ func (ed *editor) substituteArgs(result *lang.GenerateResult) ([]string, error)
for j, f := range result.Files {
allFiles[j] = f.GetPath()
}
args = append(args[:i], append(allFiles, args[i+1:]...)...)
args = slices.Replace(args, i, i+1, allFiles...)
break
}
}
Expand Down
6 changes: 2 additions & 4 deletions scripts/update_readme.go
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"os"
"slices"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -33,10 +34,7 @@ func replace(mark string, origin []byte, new []byte) []byte {
endMark := fmt.Appendf(nil, "<!-- END %s -->", mark)
begin := bytes.Index(origin, beginMark) + len(beginMark)
end := bytes.Index(origin, endMark)
result := append([]byte(nil), origin[:begin]...)
result = append(result, new...)
result = append(result, origin[end:]...)
return result
return slices.Replace(origin, begin, end, new...)
}

func updateUsage(readme []byte) []byte {
Expand Down

0 comments on commit 0fe9195

Please sign in to comment.