fix: show card only found once by prefix

This commit is contained in:
Mawu3n4 2014-08-08 14:24:29 +02:00
parent 10ab53c4ac
commit d55f6fdec1

View file

@ -718,12 +718,18 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
} }
CardInfo *CardNameMap::findByPrefix(const std::string &prefix) { CardInfo *CardNameMap::findByPrefix(const std::string &prefix) {
int count = 0;
CardInfo *found;
for (CardNameMap::iterator it = this->begin(); it != this->end(); ++it) { for (CardNameMap::iterator it = this->begin(); it != this->end(); ++it) {
if (std::mismatch(prefix.begin(), prefix.end(), if (std::mismatch(prefix.begin(), prefix.end(),
it.key().toStdString().begin()).first == prefix.end()) it.key().toStdString().begin()).first == prefix.end()) {
return it.value(); count++;
found = it.value();
} }
return NULL; }
return (count == 1 ? found : NULL);
} }
CardInfo *CardDatabase::getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound) { CardInfo *CardDatabase::getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound) {