aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/strings/strings.go
diff options
context:
space:
mode:
authorCameron Moore <[email protected]>2017-08-18 02:12:04 -0500
committerBjørn Erik Pedersen <[email protected]>2017-08-18 09:12:04 +0200
commit7674ad73825c61eecc4003475fe0577f225fe579 (patch)
tree6e0affdf18188f16cb443b1dc424eba25dd46e3d /tpl/strings/strings.go
parent08f48b91d68d3002b887ddf737456ff0cc4e786d (diff)
downloadhugo-7674ad73825c61eecc4003475fe0577f225fe579.tar.gz
hugo-7674ad73825c61eecc4003475fe0577f225fe579.zip
tpl: Add strings.TrimLeft and TrimRight
Diffstat (limited to 'tpl/strings/strings.go')
-rw-r--r--tpl/strings/strings.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/tpl/strings/strings.go b/tpl/strings/strings.go
index 5fe920433..1e1bda493 100644
--- a/tpl/strings/strings.go
+++ b/tpl/strings/strings.go
@@ -347,6 +347,22 @@ func (ns *Namespace) Trim(s, cutset interface{}) (string, error) {
return _strings.Trim(ss, sc), nil
}
+// TrimLeft returns a slice of the string s with all leading characters
+// contained in cutset removed.
+func (ns *Namespace) TrimLeft(cutset, s interface{}) (string, error) {
+ ss, err := cast.ToStringE(s)
+ if err != nil {
+ return "", err
+ }
+
+ sc, err := cast.ToStringE(cutset)
+ if err != nil {
+ return "", err
+ }
+
+ return _strings.TrimLeft(ss, sc), nil
+}
+
// TrimPrefix returns s without the provided leading prefix string. If s doesn't
// start with prefix, s is returned unchanged.
func (ns *Namespace) TrimPrefix(s, prefix interface{}) (string, error) {
@@ -363,6 +379,22 @@ func (ns *Namespace) TrimPrefix(s, prefix interface{}) (string, error) {
return _strings.TrimPrefix(ss, sx), nil
}
+// TrimRight returns a slice of the string s with all trailing characters
+// contained in cutset removed.
+func (ns *Namespace) TrimRight(cutset, s interface{}) (string, error) {
+ ss, err := cast.ToStringE(s)
+ if err != nil {
+ return "", err
+ }
+
+ sc, err := cast.ToStringE(cutset)
+ if err != nil {
+ return "", err
+ }
+
+ return _strings.TrimRight(ss, sc), nil
+}
+
// TrimSuffix returns s without the provided trailing suffix string. If s
// doesn't end with suffix, s is returned unchanged.
func (ns *Namespace) TrimSuffix(s, suffix interface{}) (string, error) {