forked from viant/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext.go
More file actions
29 lines (26 loc) · 642 Bytes
/
text.go
File metadata and controls
29 lines (26 loc) · 642 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package toolbox
import "unicode"
//IsASCIIText return true if supplied string does not have binary data
func IsASCIIText(candidate string) bool {
for _, r := range candidate {
if r == '\n' || r == '\r' || r == '\t' {
continue
}
if r > unicode.MaxASCII || !unicode.IsPrint(r) || r == '`' {
return false
}
}
return true
}
//IsPrintText return true if all candidate characters are printable (unicode.IsPrintText)
func IsPrintText(candidate string) bool {
for _, r := range candidate {
if !unicode.IsPrint(r) {
if r == '\n' || r == '\r' || r == '\t' || r == '`' {
continue
}
return false
}
}
return true
}