in wfn/wfn.go [104:130]
func WFNize(s string) (string, error) {
const allowedPunct = "-!\"#$%&'()+,./:;<=>@[]^`{|}!~"
// replace spaces with underscores
in := strings.Replace(s, " ", "_", -1)
buf := make([]byte, 0, len(in))
// remove illegal characters
for n, c := range in {
c := byte(c)
if c >= 'A' && c <= 'Z' ||
c >= 'a' && c <= 'z' ||
c >= '0' && c <= '9' ||
c == '_' ||
strings.IndexByte(allowedPunct, c) != -1 {
buf = append(buf, c)
}
// handle wildcard characters
if c == '*' || c == '?' {
if n == 0 || in[n-1] != '\\' {
buf = append(buf, '\\')
}
buf = append(buf, c)
}
}
// quote everything that requires quoting
s, _, err := addSlashesAt(string(buf), 0)
return s, err
}