aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/strings/strings.go
diff options
context:
space:
mode:
Diffstat (limited to 'tpl/strings/strings.go')
-rw-r--r--tpl/strings/strings.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/tpl/strings/strings.go b/tpl/strings/strings.go
index e6f7aed80..02f9a2b1e 100644
--- a/tpl/strings/strings.go
+++ b/tpl/strings/strings.go
@@ -162,24 +162,32 @@ func (ns *Namespace) ContainsAny(s, chars any) (bool, error) {
// ContainsNonSpace reports whether s contains any non-space characters as defined
// by Unicode's White Space property,
// <docsmeta>{"newIn": "0.111.0" }</docsmeta>
-func (ns *Namespace) ContainsNonSpace(s any) bool {
- ss := cast.ToString(s)
+func (ns *Namespace) ContainsNonSpace(s any) (bool, error) {
+ ss, err := cast.ToStringE(s)
+ if err != nil {
+ return false, err
+ }
for _, r := range ss {
if !unicode.IsSpace(r) {
- return true
+ return true, nil
}
}
- return false
+ return false, nil
}
// Diff returns an anchored diff of the two texts old and new in the “unified
// diff” format. If old and new are identical, Diff returns an empty string.
-func (ns *Namespace) Diff(oldname string, old any, newname string, new any) string {
- oldb := []byte(cast.ToString(old))
- newb := []byte(cast.ToString(new))
-
- return string(diff.Diff(oldname, oldb, newname, newb))
+func (ns *Namespace) Diff(oldname string, old any, newname string, new any) (string, error) {
+ olds, err := cast.ToStringE(old)
+ if err != nil {
+ return "", err
+ }
+ news, err := cast.ToStringE(new)
+ if err != nil {
+ return "", err
+ }
+ return string(diff.Diff(oldname, []byte(olds), newname, []byte(news))), nil
}
// HasPrefix tests whether the input s begins with prefix.