diff --git a/sphaira/source/ui/menus/appstore.cpp b/sphaira/source/ui/menus/appstore.cpp index 52dda1e..dab06f2 100644 --- a/sphaira/source/ui/menus/appstore.cpp +++ b/sphaira/source/ui/menus/appstore.cpp @@ -590,6 +590,14 @@ auto InstallApp(ProgressBox* pbox, const Entry& entry) -> bool { return true; } +// case-insensitive version of str.find() +auto FindCaseInsensitive(std::string_view base, std::string_view term) -> bool { + const auto it = std::search(base.cbegin(), base.cend(), term.cbegin(), term.cend(), [](char a, char b){ + return std::toupper(a) == std::toupper(b); + }); + return it != base.cend(); +} + } // namespace EntryMenu::EntryMenu(Entry& entry, const LazyImage& default_icon, Menu& menu) @@ -838,12 +846,6 @@ void EntryMenu::SetIndex(s64 index) { } } -auto toLower(const std::string& str) -> std::string { - std::string lower; - std::transform(str.cbegin(), str.cend(), std::back_inserter(lower), tolower); - return lower; -} - Menu::Menu(const std::vector& nro_entries) : MenuBase{"AppStore"_i18n}, m_nro_entries{nro_entries} { fs::FsNativeSd fs; fs.CreateDirectoryRecursively("/switch/sphaira/cache/appstore/icons"); @@ -1293,12 +1295,11 @@ void Menu::SetSearch(const std::string& term) { m_search_term = term; m_entries_index_search.clear(); - const auto query = toLower(m_search_term); - const auto npos = std::string::npos; + const auto query = m_search_term; for (u64 i = 0; i < m_entries.size(); i++) { const auto& e = m_entries[i]; - if (toLower(e.title).find(query) != npos || toLower(e.author).find(query) != npos || toLower(e.details).find(query) != npos || toLower(e.description).find(query) != npos) { + if (FindCaseInsensitive(e.title, query) || FindCaseInsensitive(e.author, query) || FindCaseInsensitive(e.description, query)) { m_entries_index_search.emplace_back(i); } } @@ -1327,10 +1328,11 @@ void Menu::SetAuthor() { m_author_term = m_entries[m_entries_current[m_index]].author; m_entries_index_author.clear(); + const auto query = m_author_term; for (u64 i = 0; i < m_entries.size(); i++) { const auto& e = m_entries[i]; - if (e.author.find(m_author_term) != std::string::npos) { + if (FindCaseInsensitive(e.author, query)) { m_entries_index_author.emplace_back(i); } }