diff options
author | Max Kellermann <max@musicpd.org> | 2018-11-04 13:47:13 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-11-04 13:49:47 +0100 |
commit | 6fe43ed969c9ade765f98cace4b8ac4a39c49bac (patch) | |
tree | 8b10f599c4bb4ee6d9cda60fd63ba3d11d75f465 /src/song | |
parent | b34bc066243824d6d081a067e4259b38fcf370e5 (diff) |
song/StringFilter: add flag `substring`
Prepare to stop using substrings for filter expressions.
Diffstat (limited to 'src/song')
-rw-r--r-- | src/song/StringFilter.cxx | 8 | ||||
-rw-r--r-- | src/song/StringFilter.hxx | 8 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/song/StringFilter.cxx b/src/song/StringFilter.cxx index d525e7aa1..a918d3c85 100644 --- a/src/song/StringFilter.cxx +++ b/src/song/StringFilter.cxx @@ -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; } } diff --git a/src/song/StringFilter.hxx b/src/song/StringFilter.hxx index 8c39b5f69..dd21eb100 100644 --- a/src/song/StringFilter.hxx +++ b/src/song/StringFilter.hxx @@ -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(); |