mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
feat: add IsNotBlank func (#132)
Co-authored-by: yuanyou <yuanyou@kezaihui.com>
This commit is contained in:
@@ -408,6 +408,11 @@ func IsBlank(str string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsNotBlank checks if a string is not whitespace, not empty.
|
||||
func IsNotBlank(str string) bool {
|
||||
return !IsBlank(str)
|
||||
}
|
||||
|
||||
// HasPrefixAny check if a string starts with any of a slice of specified strings.
|
||||
// Play: https://go.dev/play/p/8UUTl2C5slo
|
||||
func HasPrefixAny(str string, prefixes []string) bool {
|
||||
|
||||
@@ -479,6 +479,26 @@ func ExampleIsBlank() {
|
||||
// false
|
||||
}
|
||||
|
||||
func ExampleIsNotBlank() {
|
||||
result1 := IsNotBlank("")
|
||||
result2 := IsNotBlank(" ")
|
||||
result3 := IsNotBlank("\t\v\f\n")
|
||||
result4 := IsNotBlank(" 中文")
|
||||
result5 := IsNotBlank(" world ")
|
||||
|
||||
fmt.Println(result1)
|
||||
fmt.Println(result2)
|
||||
fmt.Println(result3)
|
||||
fmt.Println(result4)
|
||||
fmt.Println(result5)
|
||||
// Output:
|
||||
// false
|
||||
// false
|
||||
// false
|
||||
// true
|
||||
// true
|
||||
}
|
||||
|
||||
func ExampleHasPrefixAny() {
|
||||
result1 := HasPrefixAny("foo bar", []string{"fo", "xyz", "hello"})
|
||||
result2 := HasPrefixAny("foo bar", []string{"oom", "world"})
|
||||
|
||||
@@ -427,6 +427,18 @@ func TestIsBlank(t *testing.T) {
|
||||
assert.Equal(IsBlank(" 中文"), false)
|
||||
}
|
||||
|
||||
func TestIsNotBlank(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert := internal.NewAssert(t, "TestIsBlank")
|
||||
assert.Equal(IsNotBlank(""), false)
|
||||
assert.Equal(IsNotBlank(" "), false)
|
||||
assert.Equal(IsNotBlank("\t\v\f\n"), false)
|
||||
|
||||
assert.Equal(IsNotBlank(" 中文"), true)
|
||||
assert.Equal(IsNotBlank(" world "), true)
|
||||
}
|
||||
|
||||
func TestHasPrefixAny(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user