Skip to content

Commit

Permalink
fixup! Deprecate non-pipelineable strings aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhenderson committed Oct 23, 2022
1 parent a9744de commit 8fe2dbe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 10 deletions.
38 changes: 33 additions & 5 deletions docs-src/content/functions/strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,24 @@ funcs:
[bar baz foo]
- name: strings.Split
description: |
Creates a slice by splitting a string on a given delimiter.
Slices `input` into the substrings separated by `separator`, returning a
slice of the substrings between those separators. If `input` does not
contain `separator` and `separator` is not empty, returns a single-element
slice whose only element is `input`.
If `separator` is empty, it will split after each UTF-8 sequence. If
both inputs are empty (i.e. `strings.Split "" ""`), it will return an
empty slice.
This is equivalent to [`strings.SplitN`](#strings-splitn) with a `count`
of `-1`.
Note that the delimiter is not included in the resulting elements.
pipeline: true
arguments:
- name: separator
required: true
description: the string sequence to split
description: the delimiter to split on, can be multiple characters
- name: input
required: true
description: the input string
Expand All @@ -155,15 +167,31 @@ funcs:
Hello, Bart
Hello, Lisa
Hello, Maggie
- |
$ gomplate -i '{{range strings.Split "," "One,Two,Three" }}{{.}}{{"\n"}}{{end}}'
One
Two
Three
- name: strings.SplitN
description: |
Creates a slice by splitting a string on a given delimiter. The count determines
the number of substrings to return.
Slices `input` into the substrings separated by `separator`, returning a
slice of the substrings between those separators. If `input` does not
contain `separator` and `separator` is not empty, returns a single-element
slice whose only element is `input`.
The `count` determines the number of substrings to return:
* `count > 0`: at most `count` substrings; the last substring will be the
unsplit remainder.
* `count == 0`: the result is nil (zero substrings)
* `count < 0`: all substrings
See [`strings.Split`](#strings-split) for more details.
pipeline: true
arguments:
- name: separator
required: true
description: the string sequence to split
description: the delimiter to split on, can be multiple characters
- name: count
required: true
description: the maximum number of substrings to return
Expand Down
39 changes: 34 additions & 5 deletions docs/content/functions/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,19 @@ $ gomplate -i '{{ (coll.Slice "foo" "bar" "baz") | strings.Sort }}'

## `strings.Split`

Creates a slice by splitting a string on a given delimiter.
Slices `input` into the substrings separated by `separator`, returning a
slice of the substrings between those separators. If `input` does not
contain `separator` and `separator` is not empty, returns a single-element
slice whose only element is `input`.

If `separator` is empty, it will split after each UTF-8 sequence. If
both inputs are empty (i.e. `strings.Split "" ""`), it will return an
empty slice.

This is equivalent to [`strings.SplitN`](#strings-splitn) with a `count`
of `-1`.

Note that the delimiter is not included in the resulting elements.

### Usage

Expand All @@ -224,7 +236,7 @@ input | strings.Split separator

| name | description |
|------|-------------|
| `separator` | _(required)_ the string sequence to split |
| `separator` | _(required)_ the delimiter to split on, can be multiple characters |
| `input` | _(required)_ the input string |

### Examples
Expand All @@ -236,11 +248,28 @@ Hello, Bart
Hello, Lisa
Hello, Maggie
```
```console
$ gomplate -i '{{range strings.Split "," "One,Two,Three" }}{{.}}{{"\n"}}{{end}}'
One
Two
Three
```

## `strings.SplitN`

Creates a slice by splitting a string on a given delimiter. The count determines
the number of substrings to return.
Slices `input` into the substrings separated by `separator`, returning a
slice of the substrings between those separators. If `input` does not
contain `separator` and `separator` is not empty, returns a single-element
slice whose only element is `input`.

The `count` determines the number of substrings to return:

* `count > 0`: at most `count` substrings; the last substring will be the
unsplit remainder.
* `count == 0`: the result is nil (zero substrings)
* `count < 0`: all substrings

See [`strings.Split`](#strings-split) for more details.

### Usage

Expand All @@ -255,7 +284,7 @@ input | strings.SplitN separator count

| name | description |
|------|-------------|
| `separator` | _(required)_ the string sequence to split |
| `separator` | _(required)_ the delimiter to split on, can be multiple characters |
| `count` | _(required)_ the maximum number of substrings to return |
| `input` | _(required)_ the input string |

Expand Down

0 comments on commit 8fe2dbe

Please sign in to comment.