From 9c45b8e6e9abff588f3ae439cfac1b55e28faa95 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Mon, 18 Mar 2019 20:15:44 -0400 Subject: Adding strings.RuneCount function Signed-off-by: Dave Henderson --- docs-src/content/functions/strings.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'docs-src') diff --git a/docs-src/content/functions/strings.yml b/docs-src/content/functions/strings.yml index 9dbc886f..b3062dc4 100644 --- a/docs-src/content/functions/strings.yml +++ b/docs-src/content/functions/strings.yml @@ -479,6 +479,29 @@ funcs: http://example.com/a/very/long/url which should not be broken + - name: strings.RuneCount + description: | + Return the number of _runes_ (Unicode code-points) contained within the + input. This is similar to the built-in `len` function, but `len` counts + the length in _bytes_. The length of an input containing multi-byte + code-points should therefore be measured with `strings.RuneCount`. + + Inputs will first be converted to strings, and multiple inputs are + concatenated. + + This wraps Go's [`utf8.RuneCountInString`](https://golang.org/pkg/unicode/utf8/#RuneCountInString) + function. + pipeline: true + arguments: + - name: input + required: true + description: the input(s) to measure + examples: + - | + $ gomplate -i '{{ range (slice "\u03a9" "\u0030" "\u1430") }}{{ printf "%s is %d bytes and %d runes\n" . (len .) (strings.RuneCount .) }}{{ end }}' + Ω is 2 bytes and 1 runes + 0 is 1 bytes and 1 runes + ᐰ is 3 bytes and 1 runes - name: contains description: | **See [`strings.Contains`](#strings-contains) for a pipeline-compatible version** -- cgit v1.2.3