-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblank.go
49 lines (41 loc) · 996 Bytes
/
blank.go
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package blank
import (
"unicode"
)
// Remove returns the provided string with all whitespace removed.
// This includes spaces, tabs, newlines, returns, form feeds and other
// space-like characters.
//
// For more information on what is considered whitespace, visit:
// https://golang.org/pkg/unicode/#IsSpace
func Remove(str string) string {
var out []rune
for _, r := range str {
if !unicode.IsSpace(r) {
out = append(out, r)
}
}
return string(out)
}
// Is returns true if the provided string is empty or consists only of
// whitespace. Returns false otherwise.
func Is(str string) bool {
if Remove(str) == "" {
return true
}
return false
}
// Has returns true if any of the strings in the provided slice is empty
// or consists of only whitespace. If the slice is nil, returns true as well.
// Returns false otherwise.
func Has(slice []string) bool {
if len(slice) <= 0 {
return true
}
for _, s := range slice {
if Is(s) {
return true
}
}
return false
}