diff options
author | Max Kellermann <max@duempel.org> | 2013-10-29 18:54:34 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-10-29 21:13:40 +0100 |
commit | 2aee1b86f364dfc9d897939081eb4f0403f9a729 (patch) | |
tree | 1ba3e441ad69018153e266900777b2eb85b47b40 /src/SongFilter.cxx | |
parent | b5fc21b9f442904608a73e3c705e498c55769843 (diff) | |
download | mpd-2aee1b86f364dfc9d897939081eb4f0403f9a729.tar.gz mpd-2aee1b86f364dfc9d897939081eb4f0403f9a729.tar.xz mpd-2aee1b86f364dfc9d897939081eb4f0403f9a729.zip |
SongFilter: add special keyword "base"
Restores the features from the previous draft commands "findin" /
"searchin".
Diffstat (limited to 'src/SongFilter.cxx')
-rw-r--r-- | src/SongFilter.cxx | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx index 7592f2665..396bd7191 100644 --- a/src/SongFilter.cxx +++ b/src/SongFilter.cxx @@ -22,6 +22,7 @@ #include "Song.hxx" #include "tag/Tag.hxx" #include "util/ASCII.hxx" +#include "util/UriUtil.hxx" #include <glib.h> @@ -43,6 +44,9 @@ locate_parse_type(const char *str) if (StringEqualsCaseASCII(str, LOCATE_TAG_ANY_KEY)) return LOCATE_TAG_ANY_TYPE; + if (strcmp(str, "base") == 0) + return LOCATE_TAG_BASE_TYPE; + return tag_name_parse_i(str); } @@ -134,6 +138,11 @@ SongFilter::Item::Match(const Tag &_tag) const bool SongFilter::Item::Match(const Song &song) const { + if (tag == LOCATE_TAG_BASE_TYPE) { + const auto uri = song.GetURI(); + return uri_is_child_or_same(value.c_str(), uri.c_str()); + } + if (tag == LOCATE_TAG_FILE_TYPE) { const auto uri = song.GetURI(); return StringMatch(uri.c_str()); @@ -159,6 +168,14 @@ SongFilter::Parse(const char *tag_string, const char *value, bool fold_case) if (tag == TAG_NUM_OF_ITEM_TYPES) return false; + if (tag == LOCATE_TAG_BASE_TYPE) { + if (!uri_safe_local(value)) + return false; + + /* case folding doesn't work with "base" */ + fold_case = false; + } + items.push_back(Item(tag, value, fold_case)); return true; } @@ -185,3 +202,13 @@ SongFilter::Match(const Song &song) const return true; } + +std::string +SongFilter::GetBase() const +{ + for (const auto &i : items) + if (i.GetTag() == LOCATE_TAG_BASE_TYPE) + return i.GetValue(); + + return std::string(); +} |