Compare commits

..

2 Commits

Author SHA1 Message Date
c6956fe3d9 v1.0.7 2025-07-03 01:37:54 -05:00
c22772a0af improved string cleaning 2025-07-03 01:37:15 -05:00
2 changed files with 17 additions and 9 deletions

26
main.go
View File

@@ -9,7 +9,6 @@ import (
"log" "log"
"os" "os"
"path" "path"
"regexp"
"strings" "strings"
"text/template" "text/template"
"time" "time"
@@ -451,19 +450,28 @@ func moveFile(source, destination string) (err error) {
} }
func cleanPath(str string) string { 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 { 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 { func doClean(str string, mapping func(rune) rune) string {
re := regexp.MustCompile(reg) t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC, runes.Map(mapping))
s := re.ReplaceAllString(str, "") result, _, err := transform.String(t, str)
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
result, _, err := transform.String(t, s)
if err != nil { if err != nil {
panic(err) panic(err)
} }

Binary file not shown.