-
Notifications
You must be signed in to change notification settings - Fork 8
/
filename.go
31 lines (26 loc) · 919 Bytes
/
filename.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package nfo
import (
"strings"
)
var (
fileNameReplacer = strings.NewReplacer("/", "-", "\\", "-", "!", "", "?", "", ":", "", "*", "-", "|", "-", "\"", "", ">", "", "<", "")
pathNameReplacer = strings.NewReplacer("!", "", "?", "", ":", " ", ",", "", "*", "", "|", " ", "\"", "", ">", "", "<", "")
)
// FileNameCleaner return a safe file name from a given show name.
func FileNameCleaner(s string) string {
return strings.TrimSpace(fileNameReplacer.Replace(s))
}
// PathNameCleaner return a safe path name from a given show name.
func PathNameCleaner(s string) string {
if i := strings.Index(s, ":"); i >= 0 && i < 2 {
return s[:i] + strings.TrimSpace(pathNameReplacer.Replace(s[i:]))
}
return strings.TrimSpace(pathNameReplacer.Replace(s))
}
// Format2Digits return a number with 2 digits when there is only one digit
func Format2Digits(d string) string {
if len(d) < 2 {
return "0" + d
}
return d
}