1package text
2
3import (
4 "strings"
5 "unicode"
6)
7
8// Empty tell if the string is considered empty once space
9// and not graphics characters are removed
10func Empty(s string) bool {
11 trim := strings.TrimFunc(s, func(r rune) bool {
12 return unicode.IsSpace(r) || !unicode.IsGraphic(r)
13 })
14
15 return trim == ""
16}
17
18// Safe will tell if a character in the string is considered unsafe
19// Currently trigger on unicode control character except \n, \t and \r
20func Safe(s string) bool {
21 for _, r := range s {
22 switch r {
23 case '\t', '\r', '\n':
24 continue
25 }
26
27 if unicode.IsControl(r) {
28 return false
29 }
30 }
31
32 return true
33}