song/StringFilter: add flag substring

Prepare to stop using substrings for filter expressions.
This commit is contained in:
Max Kellermann 2018-11-04 13:47:13 +01:00
parent b34bc06624
commit 6fe43ed969
2 changed files with 13 additions and 3 deletions

View File

@ -32,8 +32,12 @@ StringFilter::Match(const char *s) const noexcept
#endif
if (fold_case) {
return fold_case.IsIn(s);
return substring
? fold_case.IsIn(s)
: fold_case == s;
} else {
return value == s;
return substring
? StringFind(s, value.c_str()) != nullptr
: value == s;
}
}

View File

@ -33,13 +33,19 @@ class StringFilter {
*/
IcuCompare fold_case;
/**
* Search for substrings instead of matching the whole string?
*/
bool substring;
public:
template<typename V>
StringFilter(V &&_value, bool _fold_case)
:value(std::forward<V>(_value)),
fold_case(_fold_case
? IcuCompare(value.c_str())
: IcuCompare()) {}
: IcuCompare()),
substring(_fold_case) {}
bool empty() const noexcept {
return value.empty();