diff options
Diffstat (limited to '')
-rw-r--r-- | src/SongFilter.cxx | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx index 49c966b6f..77fea606e 100644 --- a/src/SongFilter.cxx +++ b/src/SongFilter.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2013 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,12 +19,16 @@ #include "config.h" #include "SongFilter.hxx" -#include "Song.hxx" +#include "db/Song.hxx" +#include "db/LightSong.hxx" +#include "DetachedSong.hxx" #include "tag/Tag.hxx" #include "util/ASCII.hxx" #include "util/UriUtil.hxx" +#ifdef HAVE_GLIB #include <glib.h> +#endif #include <assert.h> #include <string.h> @@ -54,10 +58,15 @@ gcc_pure static std::string CaseFold(const char *p) { +#ifdef HAVE_GLIB char *q = g_utf8_casefold(p, -1); std::string result(q); g_free(q); return result; +#else + // TODO: implement without GLib + return p; +#endif } gcc_pure @@ -81,9 +90,16 @@ SongFilter::Item::StringMatch(const char *s) const assert(s != nullptr); if (fold_case) { +#ifdef HAVE_GLIB char *p = g_utf8_casefold(s, -1); +#else + // TODO: implement without GLib + const char *p = s; +#endif const bool result = strstr(p, value.c_str()) != NULL; +#ifdef HAVE_GLIB g_free(p); +#endif return result; } else { return s == value; @@ -136,7 +152,19 @@ SongFilter::Item::Match(const Tag &_tag) const } bool -SongFilter::Item::Match(const Song &song) const +SongFilter::Item::Match(const DetachedSong &song) const +{ + if (tag == LOCATE_TAG_BASE_TYPE) + return uri_is_child_or_same(value.c_str(), song.GetURI()); + + if (tag == LOCATE_TAG_FILE_TYPE) + return StringMatch(song.GetURI()); + + return Match(song.GetTag()); +} + +bool +SongFilter::Item::Match(const LightSong &song) const { if (tag == LOCATE_TAG_BASE_TYPE) { const auto uri = song.GetURI(); @@ -148,7 +176,7 @@ SongFilter::Item::Match(const Song &song) const return StringMatch(uri.c_str()); } - return song.tag != NULL && Match(*song.tag); + return Match(*song.tag); } SongFilter::SongFilter(unsigned tag, const char *value, bool fold_case) @@ -194,7 +222,17 @@ SongFilter::Parse(unsigned argc, char *argv[], bool fold_case) } bool -SongFilter::Match(const Song &song) const +SongFilter::Match(const DetachedSong &song) const +{ + for (const auto &i : items) + if (!i.Match(song)) + return false; + + return true; +} + +bool +SongFilter::Match(const LightSong &song) const { for (const auto &i : items) if (!i.Match(song)) |