Fix space as first character in directory name

This commit is contained in:
Xpl0itU 2024-03-31 19:50:55 +02:00
parent e40d499b72
commit 18d62273e8

View file

@ -5,6 +5,7 @@ import "strings"
func normalizeFilename(filename string) string {
var out strings.Builder
shouldAppend := true
firstChar := true
for _, c := range filename {
switch {
@ -13,14 +14,16 @@ func normalizeFilename(filename string) string {
out.WriteRune('_')
shouldAppend = false
}
firstChar = false
case c == ' ':
if shouldAppend {
if shouldAppend && !firstChar {
out.WriteRune(' ')
shouldAppend = false
}
case (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'):
out.WriteRune(c)
shouldAppend = true
firstChar = false
}
}