@@ -1279,6 +1279,15 @@ func builtinStrReplace(i *interpreter, strv, fromv, tov value) (value, error) {
1279
1279
return makeValueString (strings .Replace (sStr , sFrom , sTo , - 1 )), nil
1280
1280
}
1281
1281
1282
+ func builtinIsEmpty (i * interpreter , strv value ) (value , error ) {
1283
+ str , err := i .getString (strv )
1284
+ if err != nil {
1285
+ return nil , err
1286
+ }
1287
+ sStr := str .getGoString ()
1288
+ return makeValueBoolean (len (sStr ) == 0 ), nil
1289
+ }
1290
+
1282
1291
func base64DecodeGoBytes (i * interpreter , str string ) ([]byte , error ) {
1283
1292
strLen := len (str )
1284
1293
if strLen % 4 != 0 {
@@ -1495,7 +1504,7 @@ func tomlEncodeString(s string) string {
1495
1504
}
1496
1505
1497
1506
// tomlEncodeKey encodes a key - returning same string if it does not need quoting,
1498
- // otherwise return it quoted; returns empty key as ''
1507
+ // otherwise return it quoted; returns empty key as ”
1499
1508
func tomlEncodeKey (s string ) string {
1500
1509
bareAllowed := true
1501
1510
@@ -2218,6 +2227,7 @@ var funcBuiltins = buildBuiltinMap([]builtin{
2218
2227
& ternaryBuiltin {name : "substr" , function : builtinSubstr , params : ast.Identifiers {"str" , "from" , "len" }},
2219
2228
& ternaryBuiltin {name : "splitLimit" , function : builtinSplitLimit , params : ast.Identifiers {"str" , "c" , "maxsplits" }},
2220
2229
& ternaryBuiltin {name : "strReplace" , function : builtinStrReplace , params : ast.Identifiers {"str" , "from" , "to" }},
2230
+ & unaryBuiltin {name : "isEmpty" , function : builtinIsEmpty , params : ast.Identifiers {"str" }},
2221
2231
& unaryBuiltin {name : "base64Decode" , function : builtinBase64Decode , params : ast.Identifiers {"str" }},
2222
2232
& unaryBuiltin {name : "base64DecodeBytes" , function : builtinBase64DecodeBytes , params : ast.Identifiers {"str" }},
2223
2233
& unaryBuiltin {name : "parseInt" , function : builtinParseInt , params : ast.Identifiers {"str" }},
0 commit comments