diff options
author | David E. Wheeler <[email protected]> | 2018-06-04 13:47:03 -0400 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-06-04 20:47:03 +0300 |
commit | 019bd5576be87c9f06b6a928ede1a5e78677f7b3 (patch) | |
tree | 2eba3a897b200a127ccd5e2e952551e03a9c5c89 /tpl/strings/strings.go | |
parent | c3115292a7f2d2623cb45054a361e997ad9330c9 (diff) | |
download | hugo-019bd5576be87c9f06b6a928ede1a5e78677f7b3.tar.gz hugo-019bd5576be87c9f06b6a928ede1a5e78677f7b3.zip |
tpl/strings: strings.RuneCount
Diffstat (limited to 'tpl/strings/strings.go')
-rw-r--r-- | tpl/strings/strings.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tpl/strings/strings.go b/tpl/strings/strings.go index d7d8f2d85..1864bb9e0 100644 --- a/tpl/strings/strings.go +++ b/tpl/strings/strings.go @@ -57,6 +57,15 @@ func (ns *Namespace) CountRunes(s interface{}) (int, error) { return counter, nil } +// RuneCount returns the number of runes in s. +func (ns *Namespace) RuneCount(s interface{}) (int, error) { + ss, err := cast.ToStringE(s) + if err != nil { + return 0, fmt.Errorf("Failed to convert content to string: %s", err) + } + return utf8.RuneCountInString(ss), nil +} + // CountWords returns the approximate word count in s. func (ns *Namespace) CountWords(s interface{}) (int, error) { ss, err := cast.ToStringE(s) |