aboutsummaryrefslogtreecommitdiff
path: root/oop2eindopdr
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-12-25 14:25:28 +0100
committerlonkaars <loek@pipeframe.xyz>2022-12-25 14:25:28 +0100
commit7adeb14d4596e4967273eda299c803e2a828ddbd (patch)
treeae31537f75a74af441179670dc2bdb3e8ae83d17 /oop2eindopdr
parent9205f93bda48ffdc080d40140511b68b88c46fd7 (diff)
case-insensitive match
Diffstat (limited to 'oop2eindopdr')
-rw-r--r--oop2eindopdr/Pokedex.cpp10
-rw-r--r--oop2eindopdr/Pokedex.h3
2 files changed, 12 insertions, 1 deletions
diff --git a/oop2eindopdr/Pokedex.cpp b/oop2eindopdr/Pokedex.cpp
index b60b125..8a9defe 100644
--- a/oop2eindopdr/Pokedex.cpp
+++ b/oop2eindopdr/Pokedex.cpp
@@ -1,6 +1,7 @@
#include <fstream>
#include <iostream>
#include <algorithm>
+#include <cctype>
#include "CacheManager.h"
#include "DownloadManager.h"
@@ -57,12 +58,19 @@ void Pokedex::verify_collection() {
cache->update_cache();
}
+std::string Pokedex::lower(std::string input) {
+ std::string out(input.size(), ' ');
+ std::transform(input.begin(), input.end(), out.begin(), tolower);
+ return out;
+}
+
std::vector<PokemonCard*> Pokedex::search_cards_by_id_local(std::string query) {
std::vector<PokemonCard*> out(this->cards.size());
// https://cplusplus.com/reference/algorithm/copy_if/
auto it = std::copy_if(this->cards.begin(), this->cards.end(), out.begin(), [&](const PokemonCard* card) {
- return card->id.find(query) != std::string::npos || card->name.find(query) != std::string::npos;
+ return lower(card->id).find(lower(query)) != std::string::npos ||
+ lower(card->name).find(lower(query)) != std::string::npos;
});
out.resize(std::distance(out.begin(), it));
diff --git a/oop2eindopdr/Pokedex.h b/oop2eindopdr/Pokedex.h
index 41cbf7c..5fc2fc9 100644
--- a/oop2eindopdr/Pokedex.h
+++ b/oop2eindopdr/Pokedex.h
@@ -32,6 +32,9 @@ private:
virtual std::vector<PokemonCard*> search_cards_by_id_local(std::string query);
virtual std::vector<PokemonCard*> search_cards_by_id_remote(std::string query);
+ /** @brief convert std::string to lowercase */
+ std::string lower(std::string input);
+
public:
Pokedex();
virtual ~Pokedex();