diff options
author | Max Kellermann <max@musicpd.org> | 2018-11-12 12:41:29 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2018-11-12 12:49:01 +0100 |
commit | 060908d5c44ba54e0871a83973245ff44dc52103 (patch) | |
tree | 3dd3adea4f1eafd3ceb385fd409ef4254cf24481 /src/song | |
parent | 0b0f4c61f1d54eeb3a38ab04dd1757b527ae0179 (diff) |
song/Filter: add operator "contains"
Closes #410
Diffstat (limited to 'src/song')
-rw-r--r-- | src/song/Filter.cxx | 14 | ||||
-rw-r--r-- | src/song/StringFilter.hxx | 4 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/song/Filter.cxx b/src/song/Filter.cxx index 2c47ebb59..0725083a6 100644 --- a/src/song/Filter.cxx +++ b/src/song/Filter.cxx @@ -206,6 +206,20 @@ ExpectQuoted(const char *&s) static StringFilter ParseStringFilter(const char *&s, bool fold_case) { + if (auto after_contains = StringAfterPrefixIgnoreCase(s, "contains ")) { + s = StripLeft(after_contains); + auto value = ExpectQuoted(s); + return StringFilter(std::move(value), + fold_case, true, false); + } + + if (auto after_not_contains = StringAfterPrefixIgnoreCase(s, "!contains ")) { + s = StripLeft(after_not_contains); + auto value = ExpectQuoted(s); + return StringFilter(std::move(value), + fold_case, true, true); + } + bool negated = false; #ifdef HAVE_PCRE diff --git a/src/song/StringFilter.hxx b/src/song/StringFilter.hxx index 0c7c3f5e8..b01a419a5 100644 --- a/src/song/StringFilter.hxx +++ b/src/song/StringFilter.hxx @@ -96,7 +96,9 @@ public: const char *GetOperator() const noexcept { return IsRegex() ? (negated ? "!~" : "=~") - : (negated ? "!=" : "=="); + : (substring + ? (negated ? "!contains" : "contains") + : (negated ? "!=" : "==")); } gcc_pure |