hcl2: add strlen function and update docs. (#14463)
This commit is contained in:
parent
962b1f78e8
commit
813c5daa96
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:improvement
|
||||||
|
jobspec: Added `strlen` HCL2 function to determine the length of a string
|
||||||
|
```
|
|
@ -81,6 +81,7 @@ func Functions(basedir string, allowFS bool) map[string]function.Function {
|
||||||
"slice": stdlib.SliceFunc,
|
"slice": stdlib.SliceFunc,
|
||||||
"sort": stdlib.SortFunc,
|
"sort": stdlib.SortFunc,
|
||||||
"split": stdlib.SplitFunc,
|
"split": stdlib.SplitFunc,
|
||||||
|
"strlen": stdlib.StrlenFunc,
|
||||||
"strrev": stdlib.ReverseFunc,
|
"strrev": stdlib.ReverseFunc,
|
||||||
"substr": stdlib.SubstrFunc,
|
"substr": stdlib.SubstrFunc,
|
||||||
"timeadd": stdlib.TimeAddFunc,
|
"timeadd": stdlib.TimeAddFunc,
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
---
|
---
|
||||||
layout: docs
|
layout: docs
|
||||||
page_title: length - Functions - Configuration Language
|
page_title: length - Functions - Configuration Language
|
||||||
description: The length function determines the length of a collection or string.
|
description: The length function determines the length of a collection.
|
||||||
---
|
---
|
||||||
|
|
||||||
# `length` Function
|
# `length` Function
|
||||||
|
|
||||||
`length` determines the length of a given list, map, or string.
|
`length` determines the length of a given list, map, or tuple.
|
||||||
|
|
||||||
If given a list or map, the result is the number of elements in that collection.
|
If given a list, map, or tuple, the result is the number of elements in that
|
||||||
If given a string, the result is the number of characters in the string.
|
collection.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -20,21 +20,4 @@ If given a string, the result is the number of characters in the string.
|
||||||
2
|
2
|
||||||
> length({"a" = "b"})
|
> length({"a" = "b"})
|
||||||
1
|
1
|
||||||
> length("hello")
|
|
||||||
5
|
|
||||||
```
|
```
|
||||||
|
|
||||||
When given a string, the result is the number of characters, rather than the
|
|
||||||
number of bytes or Unicode sequences that form them:
|
|
||||||
|
|
||||||
```shell-session
|
|
||||||
> length("👾🕹️")
|
|
||||||
2
|
|
||||||
```
|
|
||||||
|
|
||||||
A "character" is a _grapheme cluster_, as defined by
|
|
||||||
[Unicode Standard Annex #29](http://unicode.org/reports/tr29/). Note that
|
|
||||||
remote APIs may have a different definition of "character" for the purpose of
|
|
||||||
length limits on string arguments; a Nomad provider is responsible for
|
|
||||||
translating Nomad's string representation into that used by its respective
|
|
||||||
remote system and applying any additional validation rules to it.
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
---
|
||||||
|
layout: docs
|
||||||
|
page_title: strlen - Functions - Configuration Language
|
||||||
|
description: The strlen function determines the length of a string.
|
||||||
|
---
|
||||||
|
|
||||||
|
# `strlen` Function
|
||||||
|
|
||||||
|
`strlen` determines the length of a given string.
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
strlen(string)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```shell-session
|
||||||
|
> length("hello")
|
||||||
|
5
|
||||||
|
```
|
||||||
|
|
||||||
|
When given a string, the result is the number of characters, rather than the
|
||||||
|
number of bytes or Unicode sequences that form them:
|
||||||
|
|
||||||
|
```shell-session
|
||||||
|
> length("👾🕹️")
|
||||||
|
2
|
||||||
|
```
|
||||||
|
|
||||||
|
A "character" is a _grapheme cluster_, as defined by
|
||||||
|
[Unicode Standard Annex #29](http://unicode.org/reports/tr29/). Note that
|
||||||
|
remote APIs may have a different definition of "character" for the purpose of
|
||||||
|
length limits on string arguments; a Nomad provider is responsible for
|
||||||
|
translating Nomad's string representation into that used by its respective
|
||||||
|
remote system and applying any additional validation rules to it.
|
|
@ -1322,6 +1322,10 @@
|
||||||
"title": "split",
|
"title": "split",
|
||||||
"path": "job-specification/hcl2/functions/string/split"
|
"path": "job-specification/hcl2/functions/string/split"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"title": "strlen",
|
||||||
|
"path": "job-specification/hcl2/functions/string/strlen"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"title": "strrev",
|
"title": "strrev",
|
||||||
"path": "job-specification/hcl2/functions/string/strrev"
|
"path": "job-specification/hcl2/functions/string/strrev"
|
||||||
|
|
Loading…
Reference in New Issue