yjp 1 жил өмнө
parent
commit
e4c32c74cf

+ 10 - 0
strutils/strutils.go

@@ -25,6 +25,16 @@ func HasBlank(str ...string) bool {
 	return false
 }
 
+func HasText(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

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