replace non-ascii characters in filename
This commit is contained in:
parent
7c3c21d534
commit
8f552a2440
21
finstr.go
21
finstr.go
|
@ -19,6 +19,7 @@ import (
|
|||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var dir string
|
||||
|
@ -130,8 +131,26 @@ func byModified(p []photo) func(int, int) bool {
|
|||
|
||||
/*-------------------------*/
|
||||
|
||||
func isASCII(r rune) bool {
|
||||
return r <= 127
|
||||
}
|
||||
|
||||
func convASCII(s string) string {
|
||||
out := []rune(s)
|
||||
for i, c := range out {
|
||||
if (isASCII(c) && (unicode.IsLetter(c) || unicode.IsDigit(c))) || c == '.' {
|
||||
// keep unchanged
|
||||
} else if unicode.IsSpace(c) || unicode.IsPunct(c) {
|
||||
out[i] = '-'
|
||||
} else {
|
||||
out[i] = 'x'
|
||||
}
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
func filename(s string) string {
|
||||
return url.QueryEscape(s)
|
||||
return url.QueryEscape(convASCII(s))
|
||||
}
|
||||
|
||||
func filenameDate(date calendarMonth) string {
|
||||
|
|
Loading…
Reference in New Issue
Block a user