feat: implement std.equalsIgnoreCase (#692)

This commit is contained in:
Rohit Jangid 2023-05-25 18:02:39 +05:30 committed by GitHub
parent 25d3372c98
commit 4bb6e388b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 18 deletions

View File

@ -1289,6 +1289,18 @@ func builtinIsEmpty(i *interpreter, strv value) (value, error) {
return makeValueBoolean(len(sStr) == 0), nil 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) { func base64DecodeGoBytes(i *interpreter, str string) ([]byte, error) {
strLen := len(str) strLen := len(str)
if strLen%4 != 0 { 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: "splitLimit", function: builtinSplitLimit, params: ast.Identifiers{"str", "c", "maxsplits"}},
&ternaryBuiltin{name: "strReplace", function: builtinStrReplace, params: ast.Identifiers{"str", "from", "to"}}, &ternaryBuiltin{name: "strReplace", function: builtinStrReplace, params: ast.Identifiers{"str", "from", "to"}},
&unaryBuiltin{name: "isEmpty", function: builtinIsEmpty, params: ast.Identifiers{"str"}}, &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: "base64Decode", function: builtinBase64Decode, params: ast.Identifiers{"str"}},
&unaryBuiltin{name: "base64DecodeBytes", function: builtinBase64DecodeBytes, params: ast.Identifiers{"str"}}, &unaryBuiltin{name: "base64DecodeBytes", function: builtinBase64DecodeBytes, params: ast.Identifiers{"str"}},
&unaryBuiltin{name: "parseInt", function: builtinParseInt, params: ast.Identifiers{"str"}}, &unaryBuiltin{name: "parseInt", function: builtinParseInt, params: ast.Identifiers{"str"}},

View File

@ -72,24 +72,25 @@ func prepareStdlib(g *typeGraph) {
// String Manipulation // String Manipulation
"toString": g.newSimpleFuncType(stringType, "a"), "toString": g.newSimpleFuncType(stringType, "a"),
"codepoint": g.newSimpleFuncType(numberType, "str"), "codepoint": g.newSimpleFuncType(numberType, "str"),
"char": g.newSimpleFuncType(stringType, "n"), "char": g.newSimpleFuncType(stringType, "n"),
"substr": g.newSimpleFuncType(stringType, "str", "from", "len"), "substr": g.newSimpleFuncType(stringType, "str", "from", "len"),
"findSubstr": g.newSimpleFuncType(numberArrayType, "pat", "str"), "findSubstr": g.newSimpleFuncType(numberArrayType, "pat", "str"),
"startsWith": g.newSimpleFuncType(boolType, "a", "b"), "startsWith": g.newSimpleFuncType(boolType, "a", "b"),
"endsWith": g.newSimpleFuncType(boolType, "a", "b"), "endsWith": g.newSimpleFuncType(boolType, "a", "b"),
"stripChars": g.newSimpleFuncType(stringType, "str", "chars"), "stripChars": g.newSimpleFuncType(stringType, "str", "chars"),
"lstripChars": g.newSimpleFuncType(stringType, "str", "chars"), "lstripChars": g.newSimpleFuncType(stringType, "str", "chars"),
"rstripChars": g.newSimpleFuncType(stringType, "str", "chars"), "rstripChars": g.newSimpleFuncType(stringType, "str", "chars"),
"split": g.newSimpleFuncType(arrayOfString, "str", "c"), "split": g.newSimpleFuncType(arrayOfString, "str", "c"),
"splitLimit": g.newSimpleFuncType(arrayOfString, "str", "c", "maxsplits"), "splitLimit": g.newSimpleFuncType(arrayOfString, "str", "c", "maxsplits"),
"strReplace": g.newSimpleFuncType(stringType, "str", "from", "to"), "strReplace": g.newSimpleFuncType(stringType, "str", "from", "to"),
"asciiUpper": g.newSimpleFuncType(stringType, "str"), "asciiUpper": g.newSimpleFuncType(stringType, "str"),
"asciiLower": g.newSimpleFuncType(stringType, "str"), "asciiLower": g.newSimpleFuncType(stringType, "str"),
"stringChars": g.newSimpleFuncType(stringType, "str"), "stringChars": g.newSimpleFuncType(stringType, "str"),
"format": g.newSimpleFuncType(stringType, "str", "vals"), "format": g.newSimpleFuncType(stringType, "str", "vals"),
"isEmpty": g.newSimpleFuncType(boolType, "str"), "isEmpty": g.newSimpleFuncType(boolType, "str"),
"equalsIgnoreCase": g.newSimpleFuncType(boolType, "str1", "str2"),
// TODO(sbarzowski) Fix when they match the documentation // TODO(sbarzowski) Fix when they match the documentation
"escapeStringBash": g.newSimpleFuncType(stringType, "str_"), "escapeStringBash": g.newSimpleFuncType(stringType, "str_"),
"escapeStringDollars": g.newSimpleFuncType(stringType, "str_"), "escapeStringDollars": g.newSimpleFuncType(stringType, "str_"),

View File

@ -0,0 +1 @@
true

View File

@ -0,0 +1 @@
std.equalsIgnoreCase("foo", "FOO")

View File

View File

@ -0,0 +1 @@
false

View File

@ -0,0 +1 @@
std.equalsIgnoreCase("foo", "bar")

View File