Browse Source

添加HasBlank

yjp 1 year ago
parent
commit
ab1789adcc
2 changed files with 22 additions and 0 deletions
  1. 10 0
      strutils/strutils.go
  2. 12 0
      strutils/strutils_test.go

+ 10 - 0
strutils/strutils.go

@@ -15,6 +15,16 @@ func AllBlank(str ...string) bool {
 	return true
 }
 
+func HasBlank(str ...string) bool {
+	for _, s := range str {
+		if strings.Trim(s, " ") == "" {
+			return true
+		}
+	}
+
+	return false
+}
+
 func IsStringEmpty(s string) bool {
 	return strings.Trim(s, " ") == ""
 }

+ 12 - 0
strutils/strutils_test.go

@@ -17,6 +17,18 @@ func TestAllBlank(t *testing.T) {
 	}
 }
 
+func TestHasBlank(t *testing.T) {
+	hasBlank := HasBlank("a", "", "b")
+	if !hasBlank {
+		t.Fatal("字符串包含空字符串检测失败")
+	}
+
+	hasBlank = HasBlank("a", "b", "c")
+	if hasBlank {
+		t.Fatal("字符串不包含空字符串但是检测失败")
+	}
+}
+
 func TestIsStringEmpty(t *testing.T) {
 	stringEmpty := IsStringEmpty("")
 	if !stringEmpty {