acme-dns/util.go
2016-11-11 16:48:00 +02:00

21 lines
330 B
Go

package main
import (
"regexp"
"unicode/utf8"
)
func NormalizeString(s string, len int) string {
var ret string
re, err := regexp.Compile("[^A-Za-z\\-0-9]+")
if err != nil {
log.Errorf("%v", err)
return ""
}
ret = re.ReplaceAllString(s, "")
if utf8.RuneCountInString(ret) > len {
ret = ret[0:len]
}
return ret
}