-
Notifications
You must be signed in to change notification settings - Fork 3
/
empty.go
executable file
·68 lines (58 loc) · 1.18 KB
/
empty.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package strKit
import (
"strings"
)
// IsEmpty strings.Compare比自建方法“==”的速度要快
/*
PS: 由于此方法被调用的频率较高,因此方法体内禁止调用自己写的方法,全用原生的.
*/
func IsEmpty(str string) bool {
return strings.Compare(str, "") == 0
}
func IsNotEmpty(str string) bool {
return strings.Compare(str, "") != 0
}
func IsEmptyString(obj interface{}) bool {
if str, ok := obj.(string); ok {
return IsEmpty(str)
}
return false
}
func HasEmpty(strings ...string) bool {
for _, str := range strings {
if IsEmpty(str) {
return true
}
}
return false
}
func IsAllEmpty(strings ...string) bool {
for _, str := range strings {
if IsNotEmpty(str) {
return false
}
}
return true
}
func IsAllNotEmpty(strings ...string) bool {
return !HasEmpty(strings...)
}
// EmptyToDefault
/*
@param trimArgs 是否先对 传参str 进行trim处理?(默认:false,不处理)
*/
func EmptyToDefault(str, def string, trimArgs ...bool) string {
var trimFlag bool
if trimArgs != nil {
trimFlag = trimArgs[0]
} else {
trimFlag = false
}
if trimFlag {
str = TrimSpace(str)
}
if IsEmpty(str) {
return def
}
return str
}