diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-02-21 21:54:04 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-21 21:54:04 -0500 |
| commit | 2bab08cea50a3130d2e6fea85589bf2d1bf173d1 (patch) | |
| tree | e6d558ed4b9d2875bcde6525b404791c373fc263 | |
| parent | 10528f204b45e77bff4c1427af4596615efe5aa4 (diff) | |
| parent | d2482062e26707a4e8078db92f9bb3b352c0fa7c (diff) | |
Merge pull request #497 from hairyhenderson/doc-rest-of-string-funcs
docs: adding missing string functions to yaml source
| -rw-r--r-- | docs-src/content/functions/strings.yml | 495 | ||||
| -rw-r--r-- | docs/content/functions/strings.md | 338 |
2 files changed, 758 insertions, 75 deletions
diff --git a/docs-src/content/functions/strings.yml b/docs-src/content/functions/strings.yml index aba08319..bbb9a572 100644 --- a/docs-src/content/functions/strings.yml +++ b/docs-src/content/functions/strings.yml @@ -1,6 +1,179 @@ ns: strings preamble: '' funcs: + - name: strings.Abbrev + description: | + Abbreviates a string using `...` (ellipses). Takes an optional offset from the beginning of the string, and a maximum final width (including added ellipses). + + _Also see [`strings.Trunc`](#strings-trunc)._ + pipeline: true + arguments: + - name: offset + required: false + description: offset from the start of the string. Must be `4` or greater for ellipses to be added. Defaults to `0` + - name: width + required: true + description: the desired maximum final width of the string, including ellipses + - name: input + required: true + description: the input string to abbreviate + examples: + - | + $ gomplate -i '{{ "foobarbazquxquux" | strings.Abbrev 9 }}' + foobar... + $ gomplate -i '{{ "foobarbazquxquux" | strings.Abbrev 6 9 }}' + ...baz... + - name: strings.Contains + description: | + Reports whether a substring is contained within a string. + pipeline: true + arguments: + - name: substr + required: true + description: the substring to search for + - name: input + required: true + description: the input to search + rawExamples: + - | + _`input.tmpl`:_ + ``` + {{ if (.Env.FOO | strings.Contains "f") }}yes{{else}}no{{end}} + ``` + + ```console + $ FOO=foo gomplate < input.tmpl + yes + $ FOO=bar gomplate < input.tmpl + no + ``` + - name: strings.HasPrefix + description: | + Tests whether a string begins with a certain prefix. + pipeline: true + arguments: + - name: prefix + required: true + description: the prefix to search for + - name: input + required: true + description: the input to search + examples: + - | + $ URL=http://example.com gomplate -i '{{if .Env.URL | strings.HasPrefix "https"}}foo{{else}}bar{{end}}' + bar + $ URL=https://example.com gomplate -i '{{if .Env.URL | strings.HasPrefix "https"}}foo{{else}}bar{{end}}' + foo + - name: strings.HasSuffix + description: | + Tests whether a string ends with a certain suffix. + pipeline: true + arguments: + - name: suffix + required: true + description: the suffix to search for + - name: input + required: true + description: the input to search + rawExamples: + - | + _`input.tmpl`:_ + ``` + {{.Env.URL}}{{if not (.Env.URL | strings.HasSuffix ":80")}}:80{{end}} + ``` + + ```console + $ URL=http://example.com gomplate < input.tmpl + http://example.com:80 + ``` + - name: strings.Indent + alias: indent + description: | + Indents a string. If the input string has multiple lines, each line will be indented. + pipeline: true + arguments: + - name: width + required: false + description: 'number of times to repeat the `indent` string. Default: `1`' + - name: indent + required: false + description: 'the string to indent with. Default: `" "`' + - name: input + required: true + description: the string to indent + rawExamples: + - | + This function can be especially useful when adding YAML snippets into other YAML documents, where indentation is important: + + _`input.tmpl`:_ + ``` + foo: + {{ `{"bar": {"baz": 2}}` | json | toYAML | strings.Indent " " }} + {{- `{"qux": true}` | json | toYAML | strings.Indent 2 }} + quux: + {{ `{"quuz": 42}` | json | toYAML | strings.Indent 2 " " -}} + ``` + + ```console + $ gomplate -f input.tmpl + foo: + bar: + baz: 2 + qux: true + + quux: + quuz: 42 + ``` + - name: strings.Sort + deprecated: Use [`coll.Sort`](../coll/#coll-sort) instead + description: | + Returns an alphanumerically-sorted copy of a given string list. + pipeline: true + arguments: + - name: list + required: true + description: The list to sort + examples: + - | + $ gomplate -i '{{ (slice "foo" "bar" "baz") | strings.Sort }}' + [bar baz foo] + - name: strings.Split + description: | + Creates a slice by splitting a string on a given delimiter. + pipeline: true + arguments: + - name: separator + required: true + description: the string sequence to split + - name: input + required: true + description: the input string + examples: + - | + $ gomplate -i '{{range ("Bart,Lisa,Maggie" | strings.Split ",") }}Hello, {{.}}{{end}}' + Hello, Bart + Hello, Lisa + Hello, Maggie + - name: strings.SplitN + description: | + Creates a slice by splitting a string on a given delimiter. The count determines + the number of substrings to return. + pipeline: true + arguments: + - name: separator + required: true + description: the string sequence to split + - name: count + required: true + description: the maximum number of substrings to return + - name: input + required: true + description: the input string + examples: + - | + $ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{.}}{{end}}' + foo + bar:baz - name: strings.Quote alias: quote description: | @@ -24,19 +197,61 @@ funcs: "in" $ gomplate -i '{{ strings.Quote 500 }}' "500" - - name: strings.Sort - deprecated: Use [`coll.Sort`](../coll/#coll-sort) instead + - name: strings.Repeat description: | - Returns an alphanumerically-sorted copy of a given string list. + Returns a new string consisting of `count` copies of the input string. + + It errors if `count` is negative or if the length of `input` multiplied by `count` overflows. + + This wraps Go's [`strings.Repeat`](https://golang.org/pkg/strings/#Repeat). pipeline: true arguments: - - name: list + - name: count required: true - description: The list to sort + description: the number of times to repeat the input + - name: input + required: true + description: the input to repeat examples: - | - $ gomplate -i '{{ (slice "foo" "bar" "baz") | sort }}' - [bar baz foo] + $ gomplate -i '{{ "hello " | strings.Repeat 5 }}' + hello hello hello hello hello + - name: strings.ReplaceAll + alias: replaceAll + description: | + Replaces all occurrences of a given string with another. + pipeline: true + arguments: + - name: old + required: true + description: the text to replace + - name: new + required: true + description: the new text to replace with + - name: input + required: true + description: the input to modify + examples: + - | + $ gomplate -i '{{ strings.ReplaceAll "." "-" "172.21.1.42" }}' + 172-21-1-42 + $ gomplate -i '{{ "172.21.1.42" | strings.ReplaceAll "." "-" }}' + 172-21-1-42 + - name: strings.Slug + description: | + Creates a a "slug" from a given string - supports Unicode correctly. This wraps the [github.com/gosimple/slug](https://github.com/gosimple/slug) package. See [the github.com/gosimple/slug docs](https://godoc.org/github.com/gosimple/slug) for more information. + pipeline: true + arguments: + - name: input + required: true + description: the input to "slugify" + examples: + - | + $ gomplate -i '{{ "Hello, world!" | strings.Slug }}' + hello-world + - | + $ echo 'Rock & Roll @ Cafe Wha?' | gomplate -d in=stdin: -i '{{ strings.Slug (include "in") }}' + rock-and-roll-at-cafe-wha - name: strings.Squote alias: squote description: | @@ -55,6 +270,126 @@ funcs: - | $ gomplate -i "{{ strings.Squote \"it's a banana\" }}" 'it''s a banana' + - name: strings.Title + alias: title + description: | + Convert to title-case. + pipeline: true + arguments: + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{strings.Title "hello, world!"}}' + Hello, World! + - name: strings.ToLower + alias: toLower + description: | + Convert to lower-case. + pipeline: true + arguments: + - name: input + required: true + description: the input + examples: + - | + $ echo '{{strings.ToLower "HELLO, WORLD!"}}' | gomplate + hello, world! + - name: strings.ToUpper + alias: toUpper + description: | + Convert to upper-case. + pipeline: true + arguments: + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{strings.ToUpper "hello, world!"}}' + HELLO, WORLD! + - name: strings.Trim + description: | + Trims a string by removing the given characters from the beginning and end of + the string. + pipeline: true + arguments: + - name: cutset + required: true + description: the set of characters to cut + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{ "_-foo-_" | strings.Trim "_-" }} + foo + - name: strings.TrimPrefix + description: | + Returns a string without the provided leading prefix string, if the prefix is present. + + This wraps Go's [`strings.TrimPrefix`](https://golang.org/pkg/strings/#TrimPrefix). + pipeline: true + arguments: + - name: prefix + required: true + description: the prefix to trim + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{ "hello, world" | strings.TrimPrefix "hello, " }}' + world + - name: strings.TrimSpace + alias: trimSpace + description: | + Trims a string by removing whitespace from the beginning and end of + the string. + pipeline: true + arguments: + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{ " \n\t foo" | strings.TrimSpace }}' + foo + - name: strings.TrimSuffix + description: | + Returns a string without the provided trailing suffix string, if the suffix is present. + + This wraps Go's [`strings.TrimSuffix`](https://golang.org/pkg/strings/#TrimSuffix). + pipeline: true + arguments: + - name: suffix + required: true + description: the suffix to trim + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{ "hello, world" | strings.TrimSuffix "world" }}jello' + hello, jello + - name: strings.Trunc + description: | + Returns a string truncated to the given length. + + _Also see [`strings.Abbrev`](#strings-abbrev)._ + pipeline: true + arguments: + - name: length + required: true + description: the maximum length of the output + - name: input + required: true + description: the input + examples: + - | + $ gomplate -i '{{ "hello, world" | strings.Trunc 5 }}' + hello - name: strings.CamelCase description: | Converts a sentence to CamelCase, i.e. `The quick brown fox` becomes `TheQuickBrownFox`. @@ -144,3 +479,149 @@ funcs: http://example.com/a/very/long/url which should not be broken + - name: contains + description: | + **See [`strings.Contains`](#strings-contains) for a pipeline-compatible version** + + Contains reports whether the second string is contained within the first. Equivalent to + [strings.Contains](https://golang.org/pkg/strings#Contains) + pipeline: false + arguments: + - name: input + required: true + description: the string to search + - name: substring + required: true + description: the string to search for + rawExamples: + - | + _`input.tmpl`:_ + ``` + {{if contains .Env.FOO "f"}}yes{{else}}no{{end}} + ``` + + ```console + $ FOO=foo gomplate < input.tmpl + yes + $ FOO=bar gomplate < input.tmpl + no + ``` + - name: hasPrefix + description: | + **See [`strings.HasPrefix`](#strings-hasprefix) for a pipeline-compatible version** + + Tests whether the string begins with a certain substring. Equivalent to + [strings.HasPrefix](https://golang.org/pkg/strings#HasPrefix) + pipeline: false + arguments: + - name: input + required: true + description: the string to search + - name: prefix + required: true + description: the prefix to search for + rawExamples: + - | + _`input.tmpl`:_ + ``` + {{if hasPrefix .Env.URL "https"}}foo{{else}}bar{{end}} + ``` + + ```console + $ URL=http://example.com gomplate < input.tmpl + bar + $ URL=https://example.com gomplate < input.tmpl + foo + ``` + - name: hasSuffix + description: | + **See [`strings.HasSuffix`](#strings-hassuffix) for a pipeline-compatible version** + + Tests whether the string ends with a certain substring. Equivalent to + [strings.HasSuffix](https://golang.org/pkg/strings#HasSuffix) + pipeline: false + arguments: + - name: input + required: true + description: the input to search + - name: suffix + required: true + description: the suffix to search for + rawExamples: + - | + _`input.tmpl`:_ + ``` + {{.Env.URL}}{{if not (hasSuffix .Env.URL ":80")}}:80{{end}} + ``` + + ```console + $ URL=http://example.com gomplate < input.tmpl + http://example.com:80 + ``` + - name: split + description: | + **See [`strings.Split`](#strings-split) for a pipeline-compatible version** + + Creates a slice by splitting a string on a given delimiter. Equivalent to + [strings.Split](https://golang.org/pkg/strings#Split) + pipeline: false + arguments: + - name: input + required: true + description: the input string + - name: separator + required: true + description: the string sequence to split + examples: + - | + $ gomplate -i '{{range split "Bart,Lisa,Maggie" ","}}Hello, {{.}}{{end}}' + Hello, Bart + Hello, Lisa + Hello, Maggie + - name: splitN + description: | + **See [`strings.SplitN`](#strings-splitn) for a pipeline-compatible version** + + Creates a slice by splitting a string on a given delimiter. The count determines + the number of substrings to return. Equivalent to [strings.SplitN](https://golang.org/pkg/strings#SplitN) + pipeline: false + arguments: + - name: input + required: true + description: the input string + - name: separator + required: true + description: the string sequence to split + - name: count + required: true + description: the maximum number of substrings to return + examples: + - | + $ gomplate -i '{{ range splitN "foo:bar:baz" ":" 2 }}{{.}}{{end}}' + foo + bar:baz + - name: trim + description: | + **See [`strings.Trim`](#strings-trim) for a pipeline-compatible version** + + Trims a string by removing the given characters from the beginning and end of + the string. Equivalent to [strings.Trim](https://golang.org/pkg/strings/#Trim) + pipeline: false + arguments: + - name: input + required: true + description: the input + - name: cutset + required: true + description: the set of characters to cut + rawExamples: + - | + _`input.tmpl`:_ + ``` + Hello, {{trim .Env.FOO " "}}! + ``` + + ```console + $ FOO=" world " | gomplate < input.tmpl + Hello, world! + ``` diff --git a/docs/content/functions/strings.md b/docs/content/functions/strings.md index b9c3b249..4b4c0374 100644 --- a/docs/content/functions/strings.md +++ b/docs/content/functions/strings.md @@ -5,6 +5,7 @@ menu: parent: functions --- + ## `strings.Abbrev` Abbreviates a string using `...` (ellipses). Takes an optional offset from the beginning of the string, and a maximum final width (including added ellipses). @@ -13,21 +14,22 @@ _Also see [`strings.Trunc`](#strings-trunc)._ ### Usage ```go -strings.Abbrev [offset] width input +strings.Abbrev [offset] width input ``` + ```go -input | strings.Abbrev [offset] width +input | strings.Abbrev [offset] width ``` ### Arguments -| name | description | -|--------|-------| +| name | description | +|------|-------------| | `offset` | _(optional)_ offset from the start of the string. Must be `4` or greater for ellipses to be added. Defaults to `0` | | `width` | _(required)_ the desired maximum final width of the string, including ellipses | | `input` | _(required)_ the input string to abbreviate | -### Example +### Examples ```console $ gomplate -i '{{ "foobarbazquxquux" | strings.Abbrev 9 }}' @@ -42,13 +44,21 @@ Reports whether a substring is contained within a string. ### Usage ```go -strings.Contains substr input +strings.Contains substr input ``` + ```go -input | strings.Contains substr +input | strings.Contains substr ``` -### Example +### Arguments + +| name | description | +|------|-------------| +| `substr` | _(required)_ the substring to search for | +| `input` | _(required)_ the input to search | + +### Examples _`input.tmpl`:_ ``` @@ -68,13 +78,21 @@ Tests whether a string begins with a certain prefix. ### Usage ```go -strings.HasPrefix prefix input +strings.HasPrefix prefix input ``` + ```go -input | strings.HasPrefix prefix +input | strings.HasPrefix prefix ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `prefix` | _(required)_ the prefix to search for | +| `input` | _(required)_ the input to search | + +### Examples ```console $ URL=http://example.com gomplate -i '{{if .Env.URL | strings.HasPrefix "https"}}foo{{else}}bar{{end}}' @@ -89,12 +107,20 @@ Tests whether a string ends with a certain suffix. ### Usage ```go -strings.HasSuffix suffix input +strings.HasSuffix suffix input ``` + ```go -input | strings.HasSuffix suffix +input | strings.HasSuffix suffix ``` +### Arguments + +| name | description | +|------|-------------| +| `suffix` | _(required)_ the suffix to search for | +| `input` | _(required)_ the input to search | + ### Examples _`input.tmpl`:_ @@ -115,21 +141,22 @@ Indents a string. If the input string has multiple lines, each line will be inde ### Usage ```go -strings.Indent [width] [indent] input +strings.Indent [width] [indent] input ``` + ```go -input | strings.Indent [width] [indent] +input | strings.Indent [width] [indent] ``` ### Arguments -| name | description | -|--------|-------| +| name | description | +|------|-------------| | `width` | _(optional)_ number of times to repeat the `indent` string. Default: `1` | | `indent` | _(optional)_ the string to indent with. Default: `" "` | -| `input` | the string to indent | +| `input` | _(required)_ the string to indent | -### Example +### Examples This function can be especially useful when adding YAML snippets into other YAML documents, where indentation is important: @@ -149,7 +176,7 @@ foo: baz: 2 qux: true - quux: + quux: quuz: 42 ``` @@ -186,12 +213,20 @@ Creates a slice by splitting a string on a given delimiter. ### Usage ```go -strings.Split separator input +strings.Split separator input ``` + ```go -input | strings.Split separator +input | strings.Split separator ``` +### Arguments + +| name | description | +|------|-------------| +| `separator` | _(required)_ the string sequence to split | +| `input` | _(required)_ the input string | + ### Examples ```console @@ -208,13 +243,22 @@ the number of substrings to return. ### Usage ```go -strings.SplitN separator count input +strings.SplitN separator count input ``` + ```go -input | strings.SplitN separator count +input | strings.SplitN separator count ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `separator` | _(required)_ the string sequence to split | +| `count` | _(required)_ the maximum number of substrings to return | +| `input` | _(required)_ the input string | + +### Examples ```console $ gomplate -i '{{ range ("foo:bar:baz" | strings.SplitN ":" 2) }}{{.}}{{end}}' @@ -270,17 +314,25 @@ This wraps Go's [`strings.Repeat`](https://golang.org/pkg/strings/#Repeat). ### Usage ```go -strings.Repeat count input +strings.Repeat count input ``` + ```go -input | strings.Repeat count +input | strings.Repeat count ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `count` | _(required)_ the number of times to repeat the input | +| `input` | _(required)_ the input to repeat | + +### Examples ```console -$ gomplate -i '{{ "hello, world" | strings.Repeat "world" }}jello' -hello, jello +$ gomplate -i '{{ "hello " | strings.Repeat 5 }}' +hello hello hello hello hello ``` ## `strings.ReplaceAll` @@ -291,12 +343,21 @@ Replaces all occurrences of a given string with another. ### Usage ```go -strings.ReplaceAll old new input +strings.ReplaceAll old new input ``` + ```go -input | strings.ReplaceAll old new +input | strings.ReplaceAll old new ``` +### Arguments + +| name | description | +|------|-------------| +| `old` | _(required)_ the text to replace | +| `new` | _(required)_ the new text to replace with | +| `input` | _(required)_ the input to modify | + ### Examples ```console @@ -312,17 +373,26 @@ Creates a a "slug" from a given string - supports Unicode correctly. This wraps ### Usage ```go -strings.Slug input +strings.Slug input ``` + ```go -input | strings.Slug +input | strings.Slug ``` +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input to "slugify" | + ### Examples + ```console $ gomplate -i '{{ "Hello, world!" | strings.Slug }}' hello-world - +``` +```console $ echo 'Rock & Roll @ Cafe Wha?' | gomplate -d in=stdin: -i '{{ strings.Slug (include "in") }}' rock-and-roll-at-cafe-wha ``` @@ -333,7 +403,7 @@ rock-and-roll-at-cafe-wha Surrounds an input string with a single-quote (apostrophe) character (`'`). If the input is not a string, converts first. -`'` characters in the input are first escaped in the YAML-style (by repetition: `''`). +`'` characters in the input are first escaped in the YAML-style (by repetition: `''`).<!-- ' --> ### Usage ```go @@ -369,13 +439,20 @@ Convert to title-case. ### Usage ```go -strings.Title input +strings.Title input ``` + ```go -input | strings.Title +input | strings.Title ``` -### Example +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{strings.Title "hello, world!"}}' @@ -390,13 +467,20 @@ Convert to lower-case. ### Usage ```go -strings.ToLower input +strings.ToLower input ``` + ```go -input | strings.ToLower +input | strings.ToLower ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input | + +### Examples ```console $ echo '{{strings.ToLower "HELLO, WORLD!"}}' | gomplate @@ -411,13 +495,20 @@ Convert to upper-case. ### Usage ```go -strings.ToUpper input +strings.ToUpper input ``` + ```go -input | strings.ToUpper +input | strings.ToUpper ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{strings.ToUpper "hello, world!"}}' @@ -431,13 +522,21 @@ the string. ### Usage ```go -strings.Trim cutset input +strings.Trim cutset input ``` + ```go -input | strings.Trim cutset +input | strings.Trim cutset ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `cutset` | _(required)_ the set of characters to cut | +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{ "_-foo-_" | strings.Trim "_-" }} @@ -452,13 +551,21 @@ This wraps Go's [`strings.TrimPrefix`](https://golang.org/pkg/strings/#TrimPrefi ### Usage ```go -strings.TrimPrefix prefix input +strings.TrimPrefix prefix input ``` + ```go -input | strings.TrimPrefix prefix +input | strings.TrimPrefix prefix ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `prefix` | _(required)_ the prefix to trim | +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{ "hello, world" | strings.TrimPrefix "hello, " }}' @@ -474,20 +581,26 @@ the string. ### Usage ```go -strings.TrimSpace input +strings.TrimSpace input ``` + ```go -input | strings.TrimSpace +input | strings.TrimSpace ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{ " \n\t foo" | strings.TrimSpace }}' foo ``` - ## `strings.TrimSuffix` Returns a string without the provided trailing suffix string, if the suffix is present. @@ -496,13 +609,21 @@ This wraps Go's [`strings.TrimSuffix`](https://golang.org/pkg/strings/#TrimSuffi ### Usage ```go -strings.TrimSuffix suffix input +strings.TrimSuffix suffix input ``` + ```go -input | strings.TrimSuffix suffix +input | strings.TrimSuffix suffix ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `suffix` | _(required)_ the suffix to trim | +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{ "hello, world" | strings.TrimSuffix "world" }}jello' @@ -517,13 +638,21 @@ _Also see [`strings.Abbrev`](#strings-abbrev)._ ### Usage ```go -strings.Trunc length input +strings.Trunc length input ``` + ```go -input | strings.Trunc length +input | strings.Trunc length ``` -#### Example +### Arguments + +| name | description | +|------|-------------| +| `length` | _(required)_ the maximum length of the output | +| `input` | _(required)_ the input | + +### Examples ```console $ gomplate -i '{{ "hello, world" | strings.Trunc 5 }}' @@ -640,7 +769,7 @@ The line-breaking algorithm is _naïve_ and _greedy_: lines are only broken betw When words that are longer than the desired width are encountered (e.g. long URLs), they are not broken up. Correctness is valued above line length. -The line-break sequence defaults to `\n` (i.e. the LF/Line Feed character), regardless of OS. +The line-break sequence defaults to `\n` (i.e. the LF/Line Feed character), regardless of OS. ### Usage ```go @@ -682,7 +811,19 @@ broken Contains reports whether the second string is contained within the first. Equivalent to [strings.Contains](https://golang.org/pkg/strings#Contains) -### Example +### Usage +```go +contains input substring +``` + +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the string to search | +| `substring` | _(required)_ the string to search for | + +### Examples _`input.tmpl`:_ ``` @@ -703,7 +844,19 @@ no Tests whether the string begins with a certain substring. Equivalent to [strings.HasPrefix](https://golang.org/pkg/strings#HasPrefix) -#### Example +### Usage +```go +hasPrefix input prefix +``` + +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the string to search | +| `prefix` | _(required)_ the prefix to search for | + +### Examples _`input.tmpl`:_ ``` @@ -724,7 +877,19 @@ foo Tests whether the string ends with a certain substring. Equivalent to [strings.HasSuffix](https://golang.org/pkg/strings#HasSuffix) -#### Example +### Usage +```go +hasSuffix input suffix +``` + +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input to search | +| `suffix` | _(required)_ the suffix to search for | + +### Examples _`input.tmpl`:_ ``` @@ -743,7 +908,19 @@ http://example.com:80 Creates a slice by splitting a string on a given delimiter. Equivalent to [strings.Split](https://golang.org/pkg/strings#Split) -#### Example +### Usage +```go +split input separator +``` + +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input string | +| `separator` | _(required)_ the string sequence to split | + +### Examples ```console $ gomplate -i '{{range split "Bart,Lisa,Maggie" ","}}Hello, {{.}}{{end}}' @@ -759,7 +936,20 @@ Hello, Maggie Creates a slice by splitting a string on a given delimiter. The count determines the number of substrings to return. Equivalent to [strings.SplitN](https://golang.org/pkg/strings#SplitN) -#### Example +### Usage +```go +splitN input separator count +``` + +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input string | +| `separator` | _(required)_ the string sequence to split | +| `count` | _(required)_ the maximum number of substrings to return | + +### Examples ```console $ gomplate -i '{{ range splitN "foo:bar:baz" ":" 2 }}{{.}}{{end}}' @@ -774,7 +964,19 @@ bar:baz Trims a string by removing the given characters from the beginning and end of the string. Equivalent to [strings.Trim](https://golang.org/pkg/strings/#Trim) -#### Example +### Usage +```go +trim input cutset +``` + +### Arguments + +| name | description | +|------|-------------| +| `input` | _(required)_ the input | +| `cutset` | _(required)_ the set of characters to cut | + +### Examples _`input.tmpl`:_ ``` |
