From 0a210a88964ac1005862db9f7da3fb18c842d4aa Mon Sep 17 00:00:00 2001 From: unK Date: Mon, 29 Sep 2008 00:11:00 +0200 Subject: [PATCH] use ToLower() instead of calling std::transform explicitly all the time --- src/helpers.cpp | 13 ++++++------- src/lyrics.cpp | 2 +- src/misc.cpp | 6 ++++++ src/misc.h | 2 ++ src/ncmpcpp.cpp | 4 ++-- src/search_engine.cpp | 34 +++++++++++++++++----------------- 6 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 0baa55b9..284ef362 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -18,7 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#include #include "helpers.h" #include "tag_editor.h" @@ -77,8 +76,8 @@ void UnlockStatusbar() bool CaseInsensitiveSorting::operator()(string a, string b) { - transform(a.begin(), a.end(), a.begin(), tolower); - transform(b.begin(), b.end(), b.begin(), tolower); + ToLower(a); + ToLower(b); return a < b; } @@ -86,8 +85,8 @@ bool CaseInsensitiveSorting::operator()(Song *sa, Song *sb) { string a = sa->GetName(); string b = sb->GetName(); - transform(a.begin(), a.end(), a.begin(), tolower); - transform(b.begin(), b.end(), b.begin(), tolower); + ToLower(a); + ToLower(b); return a < b; } @@ -97,8 +96,8 @@ bool CaseInsensitiveSorting::operator()(const Item &a, const Item &b) { string sa = a.type == itSong ? a.song->GetName() : a.name; string sb = b.type == itSong ? b.song->GetName() : b.name; - transform(sa.begin(), sa.end(), sa.begin(), tolower); - transform(sb.begin(), sb.end(), sb.begin(), tolower); + ToLower(sa); + ToLower(sb); return sa < sb; } else diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 4ae0f64a..fde9fed0 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -71,7 +71,7 @@ void * GetArtistInfo(void *ptr) delete strptr; string filename = artist + ".txt"; - transform(filename.begin(), filename.end(), filename.begin(), tolower); + ToLower(filename); EscapeUnallowedChars(filename); const string fullpath = artists_folder + "/" + filename; diff --git a/src/misc.cpp b/src/misc.cpp index 17705bb0..eb931054 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -18,6 +18,7 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include #include "misc.h" using std::stringstream; @@ -27,6 +28,11 @@ int Abs(int num) return (num < 0 ? -num : num); } +void ToLower(string &s) +{ + transform(s.begin(), s.end(), s.begin(), tolower); +} + int StrToInt(string str) { return atoi(str.c_str()); diff --git a/src/misc.h b/src/misc.h index ed720fd4..2ad8c685 100644 --- a/src/misc.h +++ b/src/misc.h @@ -30,6 +30,8 @@ using std::string; int Abs(int); +void ToLower(string &); + int StrToInt(string); string IntoStr(int); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index bdb3ec1c..0035576f 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -2945,13 +2945,13 @@ int main(int argc, char *argv[]) timer = time(NULL); if (findme.empty()) continue; - transform(findme.begin(), findme.end(), findme.begin(), tolower); + ToLower(findme); ShowMessage("Searching..."); for (int i = (wCurrent == mSearcher ? search_engine_static_options-1 : 0); i < wCurrent->Size(); i++) { string name = Window::OmitBBCodes(wCurrent->GetOption(i)); - transform(name.begin(), name.end(), name.begin(), tolower); + ToLower(name); if (name.find(findme) != string::npos && !wCurrent->IsStatic(i)) { vFoundPositions.push_back(i); diff --git a/src/search_engine.cpp b/src/search_engine.cpp index cb0789b6..d6c786f6 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -90,27 +90,27 @@ void Search(Song &s) { string t; t = s.GetFile(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); s.SetFile(t); t = s.GetTitle(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); s.SetTitle(t); t = s.GetArtist(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); s.SetArtist(t); t = s.GetAlbum(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); s.SetAlbum(t); t = s.GetGenre(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); s.SetGenre(t); t = s.GetComment(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); s.SetComment(t); } @@ -122,27 +122,27 @@ void Search(Song &s) { string t; t = copy.GetName(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); copy.SetFile(t); - + t = copy.GetTitle(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); copy.SetTitle(t); - + t = copy.GetArtist(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); copy.SetArtist(t); - + t = copy.GetAlbum(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); copy.SetAlbum(t); - + t = copy.GetGenre(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); copy.SetGenre(t); - + t = copy.GetComment(); - transform(t.begin(), t.end(), t.begin(), tolower); + ToLower(t); copy.SetComment(t); } else