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/playlist_editor.cpp | |
parent | 66bd3e978221e00786f170615d48189189f68070 (diff) |
replace gnu regex wrapper with boost::regex
Diffstat (limited to 'src/playlist_editor.cpp')
-rw-r--r-- | src/playlist_editor.cpp | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 523af9b0..58264414 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -51,8 +51,8 @@ size_t RightColumnStartX; size_t RightColumnWidth; std::string SongToString(const MPD::Song &s); -bool PlaylistEntryMatcher(const Regex &rx, const std::string &playlist); -bool SongEntryMatcher(const Regex &rx, const MPD::Song &s); +bool PlaylistEntryMatcher(const boost::regex &rx, const std::string &playlist); +bool SongEntryMatcher(const boost::regex &rx, const MPD::Song &s); } @@ -337,18 +337,24 @@ std::string PlaylistEditor::currentFilter() void PlaylistEditor::applyFilter(const std::string &filter) { - if (isActiveWindow(Playlists)) + try { - Playlists.showAll(); - auto rx = RegexFilter<std::string>(filter, Config.regex_type, PlaylistEntryMatcher); - Playlists.filter(Playlists.begin(), Playlists.end(), rx); - } - else if (isActiveWindow(Content)) - { - Content.showAll(); - auto rx = RegexFilter<MPD::Song>(filter, Config.regex_type, SongEntryMatcher); - Content.filter(Content.begin(), Content.end(), rx); + if (isActiveWindow(Playlists)) + { + Playlists.showAll(); + auto rx = RegexFilter<std::string>( + boost::regex(filter, Config.regex_type), PlaylistEntryMatcher); + Playlists.filter(Playlists.begin(), Playlists.end(), rx); + } + else if (isActiveWindow(Content)) + { + Content.showAll(); + auto rx = RegexFilter<MPD::Song>( + boost::regex(filter, Config.regex_type), SongEntryMatcher); + Content.filter(Content.begin(), Content.end(), rx); + } } + catch (boost::bad_expression &) { } } /***********************************************************************/ @@ -360,18 +366,27 @@ bool PlaylistEditor::allowsSearching() bool PlaylistEditor::search(const std::string &constraint) { - bool result = false; - if (isActiveWindow(Playlists)) + try { - auto rx = RegexFilter<std::string>(constraint, Config.regex_type, PlaylistEntryMatcher); - result = Playlists.search(Playlists.begin(), Playlists.end(), rx); + bool result = false; + if (isActiveWindow(Playlists)) + { + auto rx = RegexFilter<std::string>( + boost::regex(constraint, Config.regex_type), PlaylistEntryMatcher); + result = Playlists.search(Playlists.begin(), Playlists.end(), rx); + } + else if (isActiveWindow(Content)) + { + auto rx = RegexFilter<MPD::Song>( + boost::regex(constraint, Config.regex_type), SongEntryMatcher); + result = Content.search(Content.begin(), Content.end(), rx); + } + return result; } - else if (isActiveWindow(Content)) + catch (boost::bad_expression &) { - auto rx = RegexFilter<MPD::Song>(constraint, Config.regex_type, SongEntryMatcher); - result = Content.search(Content.begin(), Content.end(), rx); + return false; } - return result; } void PlaylistEditor::nextFound(bool wrap) @@ -523,14 +538,14 @@ std::string SongToString(const MPD::Song &s) return result; } -bool PlaylistEntryMatcher(const Regex &rx, const std::string &playlist) +bool PlaylistEntryMatcher(const boost::regex &rx, const std::string &playlist) { - return rx.match(playlist); + return boost::regex_search(playlist, 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); } } |