diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-03-18 20:15:44 -0400 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2019-03-18 20:15:44 -0400 |
| commit | 9c45b8e6e9abff588f3ae439cfac1b55e28faa95 (patch) | |
| tree | 4a9e4553047003ad09ede4b3047b816bad9289d0 /docs-src | |
| parent | 142279a94ed69684109f01ddfac2b5a29ba7264b (diff) | |
Adding strings.RuneCount function
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs-src')
| -rw-r--r-- | docs-src/content/functions/strings.yml | 23 |
1 files changed, 23 insertions, 0 deletions
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** |
