summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-02 21:24:52 +0200
committerMax Kellermann <max@musicpd.org>2018-08-02 21:34:29 +0200
commitb4c517c50179692bdcd7ff42f4f5c28092005c41 (patch)
tree90dd0e3b54bc82c73176c37dcf9369011ffae50f /src
parentb39bc85e60191bbcac2991d6a7ab461a194d04c6 (diff)
song/AudioFormatFilter: add mask support
Diffstat (limited to 'src')
-rw-r--r--src/song/AudioFormatSongFilter.cxx9
-rw-r--r--src/song/Filter.cxx12
2 files changed, 13 insertions, 8 deletions
diff --git a/src/song/AudioFormatSongFilter.cxx b/src/song/AudioFormatSongFilter.cxx
index 6ea8dd250..327100eb1 100644
--- a/src/song/AudioFormatSongFilter.cxx
+++ b/src/song/AudioFormatSongFilter.cxx
@@ -24,13 +24,14 @@
std::string
AudioFormatSongFilter::ToExpression() const noexcept
{
- // TODO: support mask
- return std::string("(AudioFormat == \"") + ToString(value).c_str() + "\")";
+ return std::string("(AudioFormat ") +
+ (value.IsFullyDefined() ? "==" : "=~") +
+ " \"" + ToString(value).c_str() + "\")";
}
bool
AudioFormatSongFilter::Match(const LightSong &song) const noexcept
{
- // TODO: support mask
- return song.audio_format == value;
+ return song.audio_format.IsDefined() &&
+ song.audio_format.MatchMask(value);
}
diff --git a/src/song/Filter.cxx b/src/song/Filter.cxx
index df943b8d6..ff1be66ee 100644
--- a/src/song/Filter.cxx
+++ b/src/song/Filter.cxx
@@ -245,14 +245,18 @@ SongFilter::ParseExpression(const char *&s, bool fold_case)
return std::make_unique<BaseSongFilter>(std::move(value));
} else if (type == LOCATE_TAG_AUDIO_FORMAT) {
- if (s[0] != '=' || s[1] != '=')
- throw std::runtime_error("'==' expected");
+ bool mask;
+ if (s[0] == '=' && s[1] == '=')
+ mask = false;
+ else if (s[0] == '=' && s[1] == '~')
+ mask = true;
+ else
+ throw std::runtime_error("'==' or '=~' expected");
s = StripLeft(s + 2);
- // TODO: support mask
const auto value = ParseAudioFormat(ExpectQuoted(s).c_str(),
- false);
+ mask);
if (*s != ')')
throw std::runtime_error("')' expected");