Skip to content

Commit 2eea02e

Browse files
committed
Replace -> slice
1 parent f5b7212 commit 2eea02e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Diff for: kadai2/tanaka0325/imgconv/cmd/imgconv/main.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8-
"strings"
98

109
"github.com/gopherdojo/dojo8/kadai2/tanaka0325/imgconv"
1110
)
@@ -81,7 +80,8 @@ func main() {
8180
onExit(err)
8281
}
8382
} else {
84-
fmt.Printf("%[1]s.%[2]s => %[1]s.%[3]s\n", path, from, param.ToExt)
83+
e := len(param.Path) - len(param.FromExt)
84+
fmt.Printf("%s => %s%s\n", path, path[:e], to)
8585
}
8686
}
8787
}
@@ -120,8 +120,7 @@ func getTargetFilepaths(ds []string, ext string) ([]string, error) {
120120
}
121121

122122
if filepath.Ext(name) == "."+ext {
123-
n := strings.Replace(name, "."+ext, "", -1)
124-
names = append(names, n)
123+
names = append(names, name)
125124
}
126125

127126
return nil

Diff for: kadai2/tanaka0325/imgconv/imgconv.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ConvertParam struct {
1313

1414
// Do is func to convert image format.
1515
func Do(param ConvertParam) (err error) {
16-
r, err := param.File.Open(param.Path + "." + param.FromExt)
16+
r, err := param.File.Open(param.Path)
1717
if err != nil {
1818
return
1919
}
@@ -24,7 +24,8 @@ func Do(param ConvertParam) (err error) {
2424
return
2525
}
2626

27-
w, err := param.File.Create(param.Path + "." + param.ToExt)
27+
e := len(param.Path) - len(param.FromExt)
28+
w, err := param.File.Create(param.Path[:e] + param.ToExt)
2829
if err != nil {
2930
return err
3031
}

0 commit comments

Comments
 (0)