ciao-cli: Add support for generic string matching in templates#1004
Conversation
5e5c6b9 to
8f2d4e3
Compare
| return f | ||
| } | ||
|
|
||
| func filterBySubstr(obj interface{}, field, val string) (retval interface{}) { |
There was a problem hiding this comment.
This function is almost identical to filterByField. Perhaps we need to make a new function, fieldField that takes a function as a parameter, e.g.,
func filterField(obj interface{}, field, val string, cmp func(string,string) bool)(retval interface{}) {
filterBySubstr then becomes
func filterBySubstr(obj interface{}, field, val string) (retval interface{}) {
return filterField(obj, field, val, strings.Contains)
}
filterByField
func filterByField(obj interface{}, field, val string) (retval interface{}) {
return filterField(obj, field, val, func(a, b string) bool {
return a == b
})
}
You could then have a whole pile of filter functions, with no extra effort, e.g,
filter
filterSubstr (might be better to call is filterContains to match the std lib function called)
filterHasPrefix
filterHasSuffix
filterRegexp
filterFolded
There was a problem hiding this comment.
@markdryan makes perfect sense. I will also add a few more generic filters based on what the strings suport today and with the same nomenclature. That may help in other areas also, specially event processing.
There was a problem hiding this comment.
@markdryan updated as per review comments. Please re-review
Add support for new filter capabilities. This allows the selection of list elements based on substring, prefix, suffix matching etc which will be useful for test automation. Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
8f2d4e3 to
604e734
Compare
ciao-cli: Add support for substring matching
Add support for new filter capabilities. This allows the selection
of list elements based on substring, prefix, suffix matching etc
which will be useful for test automation.