Implemeting filterting of the game list

This commit is contained in:
Maschell 2020-02-20 15:17:45 +01:00
parent 6e041490d6
commit 25a0aa54e7
3 changed files with 18 additions and 4 deletions

View File

@ -177,10 +177,9 @@ void GameList::updateTitleInfo() {
void GameList::internalFilterList(std::vector<gameInfo*> &fullList) { void GameList::internalFilterList(std::vector<gameInfo*> &fullList) {
for (uint32_t i = 0; i < fullList.size(); ++i) { for (uint32_t i = 0; i < fullList.size(); ++i) {
gameInfo *header = fullList[i]; gameInfo *header = fullList[i];
if (StringTools::findStringIC(header->name,gameFilter)) {
//! TODO: do filtering as needed filteredList.push_back(header);
}
filteredList.push_back(header);
} }
} }

View File

@ -209,3 +209,13 @@ std::vector<std::string> StringTools::stringSplit(const std::string & inValue, c
} }
return result; return result;
} }
bool StringTools::findStringIC(const std::string & strHaystack, const std::string & strNeedle)
{
auto it = std::search(
strHaystack.begin(), strHaystack.end(),
strNeedle.begin(), strNeedle.end(),
[](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }
);
return (it != strHaystack.end() );
}

View File

@ -29,6 +29,8 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <wut_types.h> #include <wut_types.h>
#include <algorithm>
#include <cctype>
class StringTools { class StringTools {
public: public:
@ -74,6 +76,9 @@ public:
} }
static std::vector<std::string> stringSplit(const std::string & value, const std::string & splitter); static std::vector<std::string> stringSplit(const std::string & value, const std::string & splitter);
// https://stackoverflow.com/a/19839371
static bool findStringIC(const std::string & strHaystack, const std::string & strNeedle);
}; };
#endif /* __STRING_TOOLS_H */ #endif /* __STRING_TOOLS_H */