vendor: update github.com/hashicorp/hcl/v2 to v2.19.1

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2023-10-19 14:49:10 +02:00
parent ad674e2666
commit 34b9a629a0
157 changed files with 20123 additions and 5438 deletions

View File

@ -14,6 +14,7 @@ import (
)
var UpperFunc = function.New(&function.Spec{
Description: "Returns the given string with all Unicode letters translated to their uppercase equivalents.",
Params: []function.Parameter{
{
Name: "str",
@ -21,7 +22,8 @@ var UpperFunc = function.New(&function.Spec{
AllowDynamicType: true,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
in := args[0].AsString()
out := strings.ToUpper(in)
@ -30,6 +32,7 @@ var UpperFunc = function.New(&function.Spec{
})
var LowerFunc = function.New(&function.Spec{
Description: "Returns the given string with all Unicode letters translated to their lowercase equivalents.",
Params: []function.Parameter{
{
Name: "str",
@ -37,7 +40,8 @@ var LowerFunc = function.New(&function.Spec{
AllowDynamicType: true,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
in := args[0].AsString()
out := strings.ToLower(in)
@ -46,6 +50,7 @@ var LowerFunc = function.New(&function.Spec{
})
var ReverseFunc = function.New(&function.Spec{
Description: "Returns the given string with all of its Unicode characters in reverse order.",
Params: []function.Parameter{
{
Name: "str",
@ -53,7 +58,8 @@ var ReverseFunc = function.New(&function.Spec{
AllowDynamicType: true,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
in := []byte(args[0].AsString())
out := make([]byte, len(in))
@ -73,48 +79,75 @@ var ReverseFunc = function.New(&function.Spec{
})
var StrlenFunc = function.New(&function.Spec{
Description: "Returns the number of Unicode characters (technically: grapheme clusters) in the given string.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
AllowUnknown: true,
AllowDynamicType: true,
},
},
Type: function.StaticReturnType(cty.Number),
RefineResult: func(b *cty.RefinementBuilder) *cty.RefinementBuilder {
// String length is never null and never negative.
// (We might refine the lower bound even more inside Impl.)
return b.NotNull().NumberRangeLowerBound(cty.NumberIntVal(0), true)
},
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
in := args[0].AsString()
l := 0
inB := []byte(in)
for i := 0; i < len(in); {
d, _, _ := textseg.ScanGraphemeClusters(inB[i:], true)
l++
i += d
if !args[0].IsKnown() {
ret := cty.UnknownVal(cty.Number)
// We may be able to still return a constrained result based on the
// refined range of the unknown value.
inRng := args[0].Range()
if inRng.TypeConstraint() == cty.String {
prefixLen := int64(graphemeClusterCount(inRng.StringPrefix()))
ret = ret.Refine().NumberRangeLowerBound(cty.NumberIntVal(prefixLen), true).NewValue()
}
return ret, nil
}
in := args[0].AsString()
l := graphemeClusterCount(in)
return cty.NumberIntVal(int64(l)), nil
},
})
func graphemeClusterCount(in string) int {
l := 0
inB := []byte(in)
for i := 0; i < len(in); {
d, _, _ := textseg.ScanGraphemeClusters(inB[i:], true)
l++
i += d
}
return l
}
var SubstrFunc = function.New(&function.Spec{
Description: "Extracts a substring from the given string.",
Params: []function.Parameter{
{
Name: "str",
Description: "The input string.",
Type: cty.String,
AllowDynamicType: true,
},
{
Name: "offset",
Description: "The starting offset in Unicode characters.",
Type: cty.Number,
AllowDynamicType: true,
},
{
Name: "length",
Description: "The maximum length of the result in Unicode characters.",
Type: cty.Number,
AllowDynamicType: true,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
in := []byte(args[0].AsString())
var offset, length int
@ -197,17 +230,21 @@ var SubstrFunc = function.New(&function.Spec{
})
var JoinFunc = function.New(&function.Spec{
Description: "Concatenates together the elements of all given lists with a delimiter, producing a single string.",
Params: []function.Parameter{
{
Name: "separator",
Type: cty.String,
Name: "separator",
Description: "Delimiter to insert between the given strings.",
Type: cty.String,
},
},
VarParam: &function.Parameter{
Name: "lists",
Type: cty.List(cty.String),
Name: "lists",
Description: "One or more lists of strings to join.",
Type: cty.List(cty.String),
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
sep := args[0].AsString()
listVals := args[1:]
@ -244,20 +281,32 @@ var JoinFunc = function.New(&function.Spec{
})
var SortFunc = function.New(&function.Spec{
Description: "Applies a lexicographic sort to the elements of the given list.",
Params: []function.Parameter{
{
Name: "list",
Type: cty.List(cty.String),
Name: "list",
Type: cty.List(cty.String),
AllowUnknown: true,
},
},
Type: function.StaticReturnType(cty.List(cty.String)),
Type: function.StaticReturnType(cty.List(cty.String)),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
listVal := args[0]
if !listVal.IsWhollyKnown() {
// If some of the element values aren't known yet then we
// can't yet predict the order of the result.
return cty.UnknownVal(retType), nil
// can't yet predict the order of the result, but we can be
// sure that the length won't change.
ret := cty.UnknownVal(retType)
if listVal.Type().IsListType() {
rng := listVal.Range()
ret = ret.Refine().
CollectionLengthLowerBound(rng.LengthLowerBound()).
CollectionLengthUpperBound(rng.LengthUpperBound()).
NewValue()
}
return ret, nil
}
if listVal.LengthInt() == 0 { // Easy path
return listVal, nil
@ -282,17 +331,21 @@ var SortFunc = function.New(&function.Spec{
})
var SplitFunc = function.New(&function.Spec{
Description: "Produces a list of one or more strings by splitting the given string at all instances of a given separator substring.",
Params: []function.Parameter{
{
Name: "separator",
Type: cty.String,
Name: "separator",
Description: "The substring that delimits the result strings.",
Type: cty.String,
},
{
Name: "str",
Type: cty.String,
Name: "str",
Description: "The string to split.",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.List(cty.String)),
Type: function.StaticReturnType(cty.List(cty.String)),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
sep := args[0].AsString()
str := args[1].AsString()
@ -311,13 +364,15 @@ var SplitFunc = function.New(&function.Spec{
// ChompFunc is a function that removes newline characters at the end of a
// string.
var ChompFunc = function.New(&function.Spec{
Description: "Removes one or more newline characters from the end of the given string.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
newlines := regexp.MustCompile(`(?:\r\n?|\n)*\z`)
return cty.StringVal(newlines.ReplaceAllString(args[0].AsString(), "")), nil
@ -327,17 +382,21 @@ var ChompFunc = function.New(&function.Spec{
// IndentFunc is a function that adds a given number of spaces to the
// beginnings of all but the first line in a given multi-line string.
var IndentFunc = function.New(&function.Spec{
Description: "Adds a given number of spaces after each newline character in the given string.",
Params: []function.Parameter{
{
Name: "spaces",
Type: cty.Number,
Name: "spaces",
Description: "Number of spaces to add after each newline character.",
Type: cty.Number,
},
{
Name: "str",
Type: cty.String,
Name: "str",
Description: "The string to transform.",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
var spaces int
if err := gocty.FromCtyValue(args[0], &spaces); err != nil {
@ -352,13 +411,15 @@ var IndentFunc = function.New(&function.Spec{
// TitleFunc is a function that converts the first letter of each word in the
// given string to uppercase.
var TitleFunc = function.New(&function.Spec{
Description: "Replaces one letter after each non-letter and non-digit character with its uppercase equivalent.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
return cty.StringVal(strings.Title(args[0].AsString())), nil
},
@ -367,13 +428,15 @@ var TitleFunc = function.New(&function.Spec{
// TrimSpaceFunc is a function that removes any space characters from the start
// and end of the given string.
var TrimSpaceFunc = function.New(&function.Spec{
Description: "Removes any consecutive space characters (as defined by Unicode) from the start and end of the given string.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
return cty.StringVal(strings.TrimSpace(args[0].AsString())), nil
},
@ -382,20 +445,27 @@ var TrimSpaceFunc = function.New(&function.Spec{
// TrimFunc is a function that removes the specified characters from the start
// and end of the given string.
var TrimFunc = function.New(&function.Spec{
Description: "Removes consecutive sequences of characters in \"cutset\" from the start and end of the given string.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
Name: "str",
Description: "The string to trim.",
Type: cty.String,
},
{
Name: "cutset",
Type: cty.String,
Name: "cutset",
Description: "A string containing all of the characters to trim. Each character is taken separately, so the order of characters is insignificant.",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
str := args[0].AsString()
cutset := args[1].AsString()
// NOTE: This doesn't properly handle any character that is encoded
// with multiple sequential code units, such as letters with
// combining diacritics and emoji modifier sequences.
return cty.StringVal(strings.Trim(str, cutset)), nil
},
})
@ -403,17 +473,21 @@ var TrimFunc = function.New(&function.Spec{
// TrimPrefixFunc is a function that removes the specified characters from the
// start the given string.
var TrimPrefixFunc = function.New(&function.Spec{
Description: "Removes the given prefix from the start of the given string, if present.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
Name: "str",
Description: "The string to trim.",
Type: cty.String,
},
{
Name: "prefix",
Type: cty.String,
Name: "prefix",
Description: "The prefix to remove, if present.",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
str := args[0].AsString()
prefix := args[1].AsString()
@ -424,17 +498,21 @@ var TrimPrefixFunc = function.New(&function.Spec{
// TrimSuffixFunc is a function that removes the specified characters from the
// end of the given string.
var TrimSuffixFunc = function.New(&function.Spec{
Description: "Removes the given suffix from the start of the given string, if present.",
Params: []function.Parameter{
{
Name: "str",
Type: cty.String,
Name: "str",
Description: "The string to trim.",
Type: cty.String,
},
{
Name: "suffix",
Type: cty.String,
Name: "suffix",
Description: "The suffix to remove, if present.",
Type: cty.String,
},
},
Type: function.StaticReturnType(cty.String),
Type: function.StaticReturnType(cty.String),
RefineResult: refineNonNull,
Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
str := args[0].AsString()
cutset := args[1].AsString()