From 25a0aa54e7e8e3c69f719d8d3e2ae69dc23d2d87 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 20 Feb 2020 15:17:45 +0100 Subject: [PATCH] Implemeting filterting of the game list --- src/game/GameList.cpp | 7 +++---- src/utils/StringTools.cpp | 10 ++++++++++ src/utils/StringTools.h | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/game/GameList.cpp b/src/game/GameList.cpp index 1d775f2..c4a4fd6 100644 --- a/src/game/GameList.cpp +++ b/src/game/GameList.cpp @@ -177,10 +177,9 @@ void GameList::updateTitleInfo() { void GameList::internalFilterList(std::vector &fullList) { for (uint32_t i = 0; i < fullList.size(); ++i) { gameInfo *header = fullList[i]; - - //! TODO: do filtering as needed - - filteredList.push_back(header); + if (StringTools::findStringIC(header->name,gameFilter)) { + filteredList.push_back(header); + } } } diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index 4ed2ba0..9dd6599 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -209,3 +209,13 @@ std::vector StringTools::stringSplit(const std::string & inValue, c } 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() ); +} diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index 1f0e336..4d5ac33 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -29,6 +29,8 @@ #include #include #include +#include +#include class StringTools { public: @@ -74,6 +76,9 @@ public: } static std::vector 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 */