From 523206579637f6c296235bfe929314bdb420a2de Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Mon, 4 Jun 2018 13:47:03 -0400 Subject: [PATCH] tpl/strings: strings.RuneCount --- content/en/functions/strings.RuneCount.md | 28 +++++++++++++++++++++++ data/docs.json | 20 +++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 content/en/functions/strings.RuneCount.md diff --git a/content/en/functions/strings.RuneCount.md b/content/en/functions/strings.RuneCount.md new file mode 100644 index 000000000..63012ab39 --- /dev/null +++ b/content/en/functions/strings.RuneCount.md @@ -0,0 +1,28 @@ +--- +title: strings.RuneCount +description: Determines the number of runes in a string. +godocref: +date: 2018-06-01 +publishdate: 2018-06-01 +lastmod: 2018-06-01 +categories: [functions] +menu: + docs: + parent: "functions" +keywords: [counting, character count, length, rune length, rune count] +signature: ["strings.RuneCount INPUT"] +workson: [] +hugoversion: +relatedfuncs: ["len", "countrunes"] +deprecated: false +aliases: [] +--- + +In contrast with `strings.CountRunes` function, which strips HTML and whitespace before counting runes, `strings.RuneCount` simply counts all the runes in a string. It relies on the Go [`utf8.RuneCountInString`] function. + +``` +{{ "Hello, 世界" | strings.RuneCount }} + +``` + +[`utf8.RuneCount`]: https://golang.org/pkg/unicode/utf8/#RuneCount \ No newline at end of file diff --git a/data/docs.json b/data/docs.json index 4eddf8eae..3020a21f2 100644 --- a/data/docs.json +++ b/data/docs.json @@ -3146,7 +3146,25 @@ "Aliases": [ "countrunes" ], - "Examples": [] + "Examples": [ + [ + "{{ \"Hello, 世界\" | countrunes }}", + "8" + ] + ] + }, + "RuneCount": { + "Description": "RuneCount returns the number of runes in s", + "Args": [ + "s" + ], + "Aliases": [], + "Examples": [ + [ + "{{ \"Hello, 世界\" | strings.RuneCount }}", + "9" + ] + ] }, "CountWords": { "Description": "CountWords returns the approximate word count in s.",