-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstringUtils.go
More file actions
84 lines (74 loc) · 1.52 KB
/
stringUtils.go
File metadata and controls
84 lines (74 loc) · 1.52 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//port ApacheCommons lang string utils
package stringUtils
import (
"regexp"
"strings"
)
// Check if string is empty
func IsEmpty(s string) bool {
if len(s) == 0 {
return true
}
return false
}
// Check if string is not empty
func IsNotEmpty(s string) bool {
return !IsEmpty(s)
}
// Check if any one of strings are empty
func IsAnyEmpty(ss ...string) bool {
for _, s := range ss {
if len(s) == 0 {
return true
}
}
return false
}
// Checks if none of the strings are empty
func IsNoneEmpty(ss ...string) bool {
for _, s := range ss {
if len(s) == 0 {
return false
}
}
return true
}
// Checks if a string is whitespace, empty ("")
func IsBlank(s string) bool {
if len(s) == 0 {
return true
}
reg := regexp.MustCompile(`^\s+$`)
actual := reg.MatchString(s)
if actual {
return true
}
return false
}
// Checks if a string is not empty (""), not null and not whitespace only.
func IsNotBlank(s string) bool {
return !IsBlank(s)
}
// Checks if any one of the strings are blank ("") or null and not whitespace only..
func IsAnyBlank(ss ...string) bool {
for _, s := range ss {
// regexp cost is probably expensive
if IsBlank((string)(s)) {
return true
}
}
return false
}
// Checks if none of the strings are blank ("") or null and whitespace only..
func IsNoneBlank(ss ...string) bool {
for _, s := range ss {
if IsBlank((string)(s)) {
return false
}
}
return true
}
// Removes control characters from both ends of this String
func Trim(str string) string {
return strings.Trim(str, " ")
}