mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-29 17:31:02 +02:00
feat: implement std.equalsIgnoreCase (#692)
This commit is contained in:
parent
25d3372c98
commit
4bb6e388b7
13
builtins.go
13
builtins.go
@ -1289,6 +1289,18 @@ func builtinIsEmpty(i *interpreter, strv value) (value, error) {
|
||||
return makeValueBoolean(len(sStr) == 0), nil
|
||||
}
|
||||
|
||||
func builtinEqualsIgnoreCase(i *interpreter, sv1, sv2 value) (value, error) {
|
||||
s1, err := i.getString(sv1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s2, err := i.getString(sv2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return makeValueBoolean(strings.EqualFold(s1.getGoString(), s2.getGoString())), nil
|
||||
}
|
||||
|
||||
func base64DecodeGoBytes(i *interpreter, str string) ([]byte, error) {
|
||||
strLen := len(str)
|
||||
if strLen%4 != 0 {
|
||||
@ -2358,6 +2370,7 @@ var funcBuiltins = buildBuiltinMap([]builtin{
|
||||
&ternaryBuiltin{name: "splitLimit", function: builtinSplitLimit, params: ast.Identifiers{"str", "c", "maxsplits"}},
|
||||
&ternaryBuiltin{name: "strReplace", function: builtinStrReplace, params: ast.Identifiers{"str", "from", "to"}},
|
||||
&unaryBuiltin{name: "isEmpty", function: builtinIsEmpty, params: ast.Identifiers{"str"}},
|
||||
&binaryBuiltin{name: "equalsIgnoreCase", function: builtinEqualsIgnoreCase, params: ast.Identifiers{"str1", "str2"}},
|
||||
&unaryBuiltin{name: "base64Decode", function: builtinBase64Decode, params: ast.Identifiers{"str"}},
|
||||
&unaryBuiltin{name: "base64DecodeBytes", function: builtinBase64DecodeBytes, params: ast.Identifiers{"str"}},
|
||||
&unaryBuiltin{name: "parseInt", function: builtinParseInt, params: ast.Identifiers{"str"}},
|
||||
|
@ -90,6 +90,7 @@ func prepareStdlib(g *typeGraph) {
|
||||
"stringChars": g.newSimpleFuncType(stringType, "str"),
|
||||
"format": g.newSimpleFuncType(stringType, "str", "vals"),
|
||||
"isEmpty": g.newSimpleFuncType(boolType, "str"),
|
||||
"equalsIgnoreCase": g.newSimpleFuncType(boolType, "str1", "str2"),
|
||||
// TODO(sbarzowski) Fix when they match the documentation
|
||||
"escapeStringBash": g.newSimpleFuncType(stringType, "str_"),
|
||||
"escapeStringDollars": g.newSimpleFuncType(stringType, "str_"),
|
||||
|
1
testdata/builtinEqualsIgnoreCase.golden
vendored
Normal file
1
testdata/builtinEqualsIgnoreCase.golden
vendored
Normal file
@ -0,0 +1 @@
|
||||
true
|
1
testdata/builtinEqualsIgnoreCase.jsonnet
vendored
Normal file
1
testdata/builtinEqualsIgnoreCase.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
||||
std.equalsIgnoreCase("foo", "FOO")
|
0
testdata/builtinEqualsIgnoreCase.linter.golden
vendored
Normal file
0
testdata/builtinEqualsIgnoreCase.linter.golden
vendored
Normal file
1
testdata/builtinEqualsIgnoreCase2.golden
vendored
Normal file
1
testdata/builtinEqualsIgnoreCase2.golden
vendored
Normal file
@ -0,0 +1 @@
|
||||
false
|
1
testdata/builtinEqualsIgnoreCase2.jsonnet
vendored
Normal file
1
testdata/builtinEqualsIgnoreCase2.jsonnet
vendored
Normal file
@ -0,0 +1 @@
|
||||
std.equalsIgnoreCase("foo", "bar")
|
0
testdata/builtinEqualsIgnoreCase2.linter.golden
vendored
Normal file
0
testdata/builtinEqualsIgnoreCase2.linter.golden
vendored
Normal file
Loading…
x
Reference in New Issue
Block a user