wombat/blog/blogutil.go

26 lines
435 B
Go
Raw Normal View History

2019-01-01 19:41:03 +01:00
package blog
import (
"unicode"
)
const TimeFormat string = "2006-01-02 15:04"
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)
}