Commit 6fe43ed9 authored by Max Kellermann's avatar Max Kellermann

song/StringFilter: add flag `substring`

Prepare to stop using substrings for filter expressions.
parent b34bc066
...@@ -32,8 +32,12 @@ StringFilter::Match(const char *s) const noexcept ...@@ -32,8 +32,12 @@ StringFilter::Match(const char *s) const noexcept
#endif #endif
if (fold_case) { if (fold_case) {
return fold_case.IsIn(s); return substring
? fold_case.IsIn(s)
: fold_case == s;
} else { } else {
return value == s; return substring
? StringFind(s, value.c_str()) != nullptr
: value == s;
} }
} }
...@@ -33,13 +33,19 @@ class StringFilter { ...@@ -33,13 +33,19 @@ class StringFilter {
*/ */
IcuCompare fold_case; IcuCompare fold_case;
/**
* Search for substrings instead of matching the whole string?
*/
bool substring;
public: public:
template<typename V> template<typename V>
StringFilter(V &&_value, bool _fold_case) StringFilter(V &&_value, bool _fold_case)
:value(std::forward<V>(_value)), :value(std::forward<V>(_value)),
fold_case(_fold_case fold_case(_fold_case
? IcuCompare(value.c_str()) ? IcuCompare(value.c_str())
: IcuCompare()) {} : IcuCompare()),
substring(_fold_case) {}
bool empty() const noexcept { bool empty() const noexcept {
return value.empty(); return value.empty();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment