SongFilter: implement the AND operator

This commit is contained in:
Max Kellermann 2018-07-25 07:52:38 +02:00
parent 7a8d5070f5
commit 7aa8497546
2 changed files with 24 additions and 1 deletions

View File

@ -268,6 +268,13 @@
time stamp).
</para>
</listitem>
<listitem>
<para>
"<code>EXPRESSION1 AND EXPRESSION2 ...</code>": combine two or
more expressions with logical "and".
</para>
</listitem>
</itemizedlist>
<para>

View File

@ -334,7 +334,23 @@ SongFilter::ParseExpression(const char *&s, bool fold_case)
return first;
}
throw std::runtime_error("Nested expressions not yet implemented");
if (ExpectWord(s) != "AND")
throw std::runtime_error("'AND' expected");
auto and_filter = std::make_unique<AndSongFilter>();
and_filter->AddItem(std::move(first));
while (true) {
and_filter->AddItem(ParseExpression(s, fold_case));
if (*s == ')') {
++s;
return and_filter;
}
if (ExpectWord(s) != "AND")
throw std::runtime_error("'AND' expected");
}
}
auto type = ExpectFilterType(s);