linsk/utils/utils.go

25 lines
408 B
Go
Raw Normal View History

2023-08-25 15:12:19 +01:00
package utils
import (
2023-08-25 16:54:58 +01:00
"regexp"
2023-08-25 15:12:19 +01:00
"strings"
"unicode"
)
func ClearUnprintableChars(s string) string {
return strings.Map(func(r rune) rune {
if unicode.IsPrint(r) {
return r
}
return -1
}, s)
}
2023-08-25 16:54:58 +01:00
var devNameRegexp = regexp.MustCompile("^[0-9a-z_-]+$")
func ValidateDevName(s string) bool {
// Allow mapped devices.
s = strings.TrimPrefix(s, "mapper/")
return devNameRegexp.MatchString(s)
}