Skip to content

Commit 756d008

Browse files
committed
Improve string splitting
1 parent 462498f commit 756d008

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

goreplace.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,8 @@ func generateTemplateData(changesets []changeset) (templateData) {
437437

438438
// add env variables
439439
for _, e := range os.Environ() {
440-
pair := strings.Split(e, "=")
441-
442-
envKey := pair[0]
443-
envValue := strings.Join(pair[1:], "=")
444-
440+
split := strings.SplitN(e, "=", 2)
441+
envKey, envValue := split[0], split[1]
445442
ret.Env[envKey] = envValue
446443
}
447444

@@ -593,10 +590,10 @@ func buildFileitems(args []string) ([]fileitem) {
593590
file.Output = strings.TrimSuffix(file.Output, opts.OutputStripFileExt)
594591
} else if strings.Contains(filepath, ":") {
595592
// argument like "source:destination"
596-
pair := strings.Split(filepath, ":")
593+
split := strings.SplitN(filepath, ":", 2)
597594

598-
file.Path = pair[0]
599-
file.Output = pair[1]
595+
file.Path = split[0]
596+
file.Output = split[1]
600597
}
601598

602599
fileitems = append(fileitems, file)

0 commit comments

Comments
 (0)