diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2023-01-16 18:56:44 +0100 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2023-01-20 16:02:11 +0100 |
commit | d567b848e57686f631b0a0c081126bea578838c2 (patch) | |
tree | 1f83e6c0c677a8f1d44c6b336c0dbcdbf865f93a | |
parent | 00e83e04d35a7ca17b9500fc9da6da2289c078c1 (diff) | |
download | rules-cc-d567b848e57686f631b0a0c081126bea578838c2.tar.gz |
Expression "contains" supports prefix and return
-rw-r--r-- | EXPRESSIONS | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/EXPRESSIONS b/EXPRESSIONS index 55976f4..c84ebf4 100644 --- a/EXPRESSIONS +++ b/EXPRESSIONS @@ -227,18 +227,49 @@ } } , "contains": - { "vars": ["list", "item"] + { "doc": ["Returns the item if it is in the list or \"null\" otherwise."] + , "vars": ["list", "item", "list_prefix"] + , "vars_doc": + { "list": ["The list to look for the item."] + , "item": ["The item to look for in the list."] + , "list_prefix": + [ "An optional string, which every item in the list is prefixed with" + , "before comparison. Note that the returned item is not prefixed." + ] + } , "expression": - { "type": "or" - , "$1": - { "type": "foreach" - , "var": "entry" - , "range": {"type": "var", "name": "list"} - , "body": - { "type": "==" - , "$1": {"type": "var", "name": "entry"} - , "$2": {"type": "var", "name": "item"} - } + { "type": "let*" + , "bindings": + [ [ "result" + , { "type": "++" + , "$1": + { "type": "foreach" + , "var": "entry" + , "range": {"type": "var", "name": "list"} + , "body": + { "type": "if" + , "cond": + { "type": "==" + , "$1": + { "type": "join" + , "$1": + [ {"type": "var", "name": "list_prefix", "default": ""} + , {"type": "var", "name": "entry"} + ] + } + , "$2": {"type": "var", "name": "item"} + } + , "then": [{"type": "var", "name": "entry"}] + } + } + } + ] + ] + , "body": + { "type": "if" + , "cond": {"type": "var", "name": "result"} + , "then": {"type": "join", "$1": {"type": "var", "name": "result"}} + , "else": null } } } |