"html/template"
"regexp"
"strings"
+ "unicode"
"unicode/utf8"
"github.com/gohugoio/hugo/common/text"
return strings.ContainsAny(ss, sc), nil
}
+// ContainsNonSpace reports whether s contains any non-space characters as defined
+// by Unicode's White Space property,
+func (ns *Namespace) ContainsNonSpace(s any) bool {
+ ss := cast.ToString(s)
+
+ for _, r := range ss {
+ if !unicode.IsSpace(r) {
+ return true
+ }
+ }
+ return false
+}
+
// HasPrefix tests whether the input s begins with prefix.
func (ns *Namespace) HasPrefix(s, prefix any) (bool, error) {
ss, err := cast.ToStringE(s)
}
}
+func TestContainsNonSpace(t *testing.T) {
+ t.Parallel()
+ c := qt.New(t)
+
+ for _, test := range []struct {
+ s any
+ expect bool
+ }{
+ {"", false},
+ {" ", false},
+ {" ", false},
+ {"\t", false},
+ {"\r", false},
+ {"a", true},
+ {" a", true},
+ {"a\n", true},
+ } {
+ c.Assert(ns.ContainsNonSpace(test.s), qt.Equals, test.expect)
+ }
+}
+
func TestCountRunes(t *testing.T) {
t.Parallel()
c := qt.New(t)