summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-04-14 09:46:23 (GMT)
committerRichard Maudsley <richard.maudsley@isode.com>2014-04-25 08:38:24 (GMT)
commitd5f701fdd6826421c0c83b8e299918065b6c99d1 (patch)
tree90d5c425b8dda4c293e3e902ad9cea4f7750430f /Swift/Controllers/ContactSuggester.cpp
parente4704555946626980014d936dcfe6ede2710501b (diff)
downloadswift-d5f701fdd6826421c0c83b8e299918065b6c99d1.zip
swift-d5f701fdd6826421c0c83b8e299918065b6c99d1.tar.bz2
Sort ContactSuggester results using case-insensitive substring match, plus unit tests.
Change-Id: I806f696dac582ba2d818ceb22df3a10495ce0b16
Diffstat (limited to 'Swift/Controllers/ContactSuggester.cpp')
-rw-r--r--Swift/Controllers/ContactSuggester.cpp26
1 files changed, 6 insertions, 20 deletions
diff --git a/Swift/Controllers/ContactSuggester.cpp b/Swift/Controllers/ContactSuggester.cpp
index 41e0261..09a1567 100644
--- a/Swift/Controllers/ContactSuggester.cpp
+++ b/Swift/Controllers/ContactSuggester.cpp
@@ -12,7 +12,9 @@
#include <Swift/Controllers/ContactSuggester.h>
+#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/find.hpp>
+#include <boost/bind.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
@@ -51,11 +53,11 @@ std::vector<Contact::ref> ContactSuggester::getSuggestions(const std::string& se
append(results, provider->getContacts());
}
- std::sort(results.begin(), results.end(), ContactSuggester::contactLexicographicalSortPredicate);
- results.erase(std::unique(results.begin(), results.end(), ContactSuggester::contactEqualityPredicate), results.end());
- results.erase(std::remove_if(results.begin(), results.end(), !lambda::bind(&ContactSuggester::matchContact, search, lambda::_1)),
+ std::sort(results.begin(), results.end(), Contact::lexicographicalSortPredicate);
+ results.erase(std::unique(results.begin(), results.end(), Contact::equalityPredicate), results.end());
+ results.erase(std::remove_if(results.begin(), results.end(), !lambda::bind(&matchContact, search, lambda::_1)),
results.end());
- std::sort(results.begin(), results.end(), ContactSuggester::contactSmartSortPredicate);
+ std::sort(results.begin(), results.end(), boost::bind(&Contact::sortPredicate, _1, _2, search));
return results;
}
@@ -72,20 +74,4 @@ bool ContactSuggester::fuzzyMatch(std::string text, std::string match) {
return true;
}
-bool ContactSuggester::contactLexicographicalSortPredicate(const Contact::ref& a, const Contact::ref& b) {
- return a->jid < b->jid;
-}
-
-bool ContactSuggester::contactEqualityPredicate(const Contact::ref& a, const Contact::ref& b) {
- return a->jid == b->jid;
-}
-
-bool ContactSuggester::contactSmartSortPredicate(const Contact::ref& a, const Contact::ref& b) {
- if (a->statusType == b->statusType) {
- return a->name.compare(b->name) < 0;
- } else {
- return a->statusType < b->statusType;
- }
-}
-
}