diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2013-04-06 16:47:03 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2013-04-06 16:47:03 +0200 |
commit | 2b5f1b9fd438776f95c880c97b3d08a339139c79 (patch) | |
tree | 870b1cb5c06911f820d96d49f71cf8002814d336 /src/media_library.cpp | |
parent | 66bd3e978221e00786f170615d48189189f68070 (diff) |
replace gnu regex wrapper with boost::regex
Diffstat (limited to 'src/media_library.cpp')
-rw-r--r-- | src/media_library.cpp | 97 |
1 files changed, 57 insertions, 40 deletions
diff --git a/src/media_library.cpp b/src/media_library.cpp index 81580f56..4d7ea8fc 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -61,9 +61,9 @@ typedef MediaLibrary::AlbumEntry AlbumEntry; std::string AlbumToString(const AlbumEntry &ae); std::string SongToString(const MPD::Song &s); -bool TagEntryMatcher(const Regex &rx, const MediaLibrary::PrimaryTag &tagmtime); -bool AlbumEntryMatcher(const Regex &rx, const NC::Menu<AlbumEntry>::Item &item, bool filter); -bool SongEntryMatcher(const Regex &rx, const MPD::Song &s); +bool TagEntryMatcher(const boost::regex &rx, const MediaLibrary::PrimaryTag &tagmtime); +bool AlbumEntryMatcher(const boost::regex &rx, const NC::Menu<AlbumEntry>::Item &item, bool filter); +bool SongEntryMatcher(const boost::regex &rx, const MPD::Song &s); struct SortSongs { typedef NC::Menu<MPD::Song>::Item SongItem; @@ -563,25 +563,32 @@ std::string MediaLibrary::currentFilter() void MediaLibrary::applyFilter(const std::string &filter) { - if (isActiveWindow(Tags)) - { - Tags.showAll(); - auto rx = RegexFilter<PrimaryTag>(filter, Config.regex_type, TagEntryMatcher); - Tags.filter(Tags.begin(), Tags.end(), rx); - } - else if (isActiveWindow(Albums)) + try { - Albums.showAll(); - auto fun = std::bind(AlbumEntryMatcher, _1, _2, true); - auto rx = RegexItemFilter<AlbumEntry>(filter, Config.regex_type, fun); - Albums.filter(Albums.begin(), Albums.end(), rx); - } - else if (isActiveWindow(Songs)) - { - Songs.showAll(); - auto rx = RegexFilter<MPD::Song>(filter, Config.regex_type, SongEntryMatcher); - Songs.filter(Songs.begin(), Songs.end(), rx); + if (isActiveWindow(Tags)) + { + Tags.showAll(); + auto rx = RegexFilter<PrimaryTag>( + boost::regex(filter, Config.regex_type), TagEntryMatcher); + Tags.filter(Tags.begin(), Tags.end(), rx); + } + else if (isActiveWindow(Albums)) + { + Albums.showAll(); + auto fun = std::bind(AlbumEntryMatcher, _1, _2, true); + auto rx = RegexItemFilter<AlbumEntry>( + boost::regex(filter, Config.regex_type), fun); + Albums.filter(Albums.begin(), Albums.end(), rx); + } + else if (isActiveWindow(Songs)) + { + Songs.showAll(); + auto rx = RegexFilter<MPD::Song>( + boost::regex(filter, Config.regex_type), SongEntryMatcher); + Songs.filter(Songs.begin(), Songs.end(), rx); + } } + catch (boost::bad_expression &) { } } /***********************************************************************/ @@ -593,24 +600,34 @@ bool MediaLibrary::allowsSearching() bool MediaLibrary::search(const std::string &constraint) { - bool result = false; - if (isActiveWindow(Tags)) - { - auto rx = RegexFilter<PrimaryTag>(constraint, Config.regex_type, TagEntryMatcher); - result = Tags.search(Tags.begin(), Tags.end(), rx); - } - else if (isActiveWindow(Albums)) + try { - auto fun = std::bind(AlbumEntryMatcher, _1, _2, false); - auto rx = RegexItemFilter<AlbumEntry>(constraint, Config.regex_type, fun); - result = Albums.search(Albums.begin(), Albums.end(), rx); + bool result = false; + if (isActiveWindow(Tags)) + { + auto rx = RegexFilter<PrimaryTag>( + boost::regex(constraint, Config.regex_type), TagEntryMatcher); + result = Tags.search(Tags.begin(), Tags.end(), rx); + } + else if (isActiveWindow(Albums)) + { + auto fun = std::bind(AlbumEntryMatcher, _1, _2, false); + auto rx = RegexItemFilter<AlbumEntry>( + boost::regex(constraint, Config.regex_type), fun); + result = Albums.search(Albums.begin(), Albums.end(), rx); + } + else if (isActiveWindow(Songs)) + { + auto rx = RegexFilter<MPD::Song>( + boost::regex(constraint, Config.regex_type), SongEntryMatcher); + result = Songs.search(Songs.begin(), Songs.end(), rx); + } + return result; } - else if (isActiveWindow(Songs)) + catch (boost::bad_expression &) { - auto rx = RegexFilter<MPD::Song>(constraint, Config.regex_type, SongEntryMatcher); - result = Songs.search(Songs.begin(), Songs.end(), rx); + return false; } - return result; } void MediaLibrary::nextFound(bool wrap) @@ -1010,21 +1027,21 @@ std::string SongToString(const MPD::Song &s) return s.toString(Config.song_library_format, Config.tags_separator); } -bool TagEntryMatcher(const Regex &rx, const MediaLibrary::PrimaryTag &pt) +bool TagEntryMatcher(const boost::regex &rx, const MediaLibrary::PrimaryTag &pt) { - return rx.match(pt.tag()); + return boost::regex_search(pt.tag(), rx); } -bool AlbumEntryMatcher(const Regex &rx, const NC::Menu<AlbumEntry>::Item &item, bool filter) +bool AlbumEntryMatcher(const boost::regex &rx, const NC::Menu<AlbumEntry>::Item &item, bool filter) { if (item.isSeparator() || item.value().isAllTracksEntry()) return filter; - return rx.match(AlbumToString(item.value())); + return boost::regex_search(AlbumToString(item.value()), rx); } -bool SongEntryMatcher(const Regex &rx, const MPD::Song &s) +bool SongEntryMatcher(const boost::regex &rx, const MPD::Song &s) { - return rx.match(SongToString(s)); + return boost::regex_search(SongToString(s), rx); } } |