mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
tpl/strings: Add strings.ContainsNonSpace
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"html/template"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/gohugoio/hugo/common/text"
|
||||
@@ -160,6 +161,19 @@ func (ns *Namespace) ContainsAny(s, chars any) (bool, error) {
|
||||
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)
|
||||
|
Reference in New Issue
Block a user