From 4208c8cd889112aa1adffaa2b6492f61734d1105 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 24 Sep 2011 17:13:07 +0300 Subject: Replace compare function in who is online to functuator. --- src/gui/whoisonline.cpp | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'src/gui') diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index e1f69c2d7..a14e99afc 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -59,23 +59,27 @@ #undef malloc #endif -bool stringCompare(const std::string &left, const std::string &right); -bool stringCompare(const std::string &left, const std::string &right ) +class NameFunctuator { - for (std::string::const_iterator lit = left.begin(), - rit = right.begin(); - lit != left.end() && rit != right.end(); ++lit, ++rit) - { - if (tolower(*lit) < tolower(*rit)) - return true; - else if (tolower(*lit) > tolower(*rit)) + public: + bool operator()(const std::string &left, + const std::string &right) const + { + for (std::string::const_iterator lit = left.begin(), + rit = right.begin(); + lit != left.end() && rit != right.end(); ++lit, ++rit) + { + if (tolower(*lit) < tolower(*rit)) + return true; + else if (tolower(*lit) > tolower(*rit)) + return false; + } + if (left.size() < right.size()) + return true; return false; - } - if (left.size() < right.size()) - return true; - return false; -} + } +} nameCompare; WhoIsOnline::WhoIsOnline(): Window(_("Who Is Online - Updating"), false, 0, "whoisonline.xml"), @@ -297,9 +301,9 @@ void WhoIsOnline::loadList() setCaption(_("Who Is Online - ") + toString(numOnline)); //List the online people - sort(friends.begin(), friends.end(), stringCompare); - sort(neutral.begin(), neutral.end(), stringCompare); - sort(disregard.begin(), disregard.end(), stringCompare); + sort(friends.begin(), friends.end(), nameCompare); + sort(neutral.begin(), neutral.end(), nameCompare); + sort(disregard.begin(), disregard.end(), nameCompare); bool addedFromSection(false); for (int i = 0; i < static_cast(friends.size()); i++) { -- cgit v1.2.3-70-g09d2