Compare commits
2 Commits
73502669ea
...
c6956fe3d9
| Author | SHA1 | Date | |
|---|---|---|---|
| c6956fe3d9 | |||
| c22772a0af |
26
main.go
26
main.go
@@ -9,7 +9,6 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
@@ -451,19 +450,28 @@ func moveFile(source, destination string) (err error) {
|
||||
}
|
||||
|
||||
func cleanPath(str string) string {
|
||||
return doClean(str, `[<>:"|?*]`)
|
||||
return doClean(str, func(r rune) rune {
|
||||
switch r {
|
||||
case '<', '>', ':', '\'', '"', '|', '?', '*':
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
})
|
||||
}
|
||||
|
||||
func cleanTemplateVariable(str string) string {
|
||||
return doClean(str, `[<>:"|?*/\\.]`)
|
||||
return doClean(str, func(r rune) rune {
|
||||
switch r {
|
||||
case '<', '>', ':', '\'', '"', '|', '?', '*', '/', '\\', '.':
|
||||
return '_'
|
||||
}
|
||||
return r
|
||||
})
|
||||
}
|
||||
|
||||
func doClean(str string, reg string) string {
|
||||
re := regexp.MustCompile(reg)
|
||||
s := re.ReplaceAllString(str, "")
|
||||
|
||||
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
|
||||
result, _, err := transform.String(t, s)
|
||||
func doClean(str string, mapping func(rune) rune) string {
|
||||
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC, runes.Map(mapping))
|
||||
result, _, err := transform.String(t, str)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
BIN
music-rename
BIN
music-rename
Binary file not shown.
Reference in New Issue
Block a user