From ed09da49dfb753e8a6347d9b9a85ec725be3f388 Mon Sep 17 00:00:00 2001 From: colinmendoza121 Date: Fri, 21 Feb 2025 20:19:17 -0500 Subject: [PATCH] Added CompareStringsCaseInsesitive helper function --- src/qt_gui/game_list_frame.h | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/qt_gui/game_list_frame.h b/src/qt_gui/game_list_frame.h index 5438c6fec..d22492c23 100644 --- a/src/qt_gui/game_list_frame.h +++ b/src/qt_gui/game_list_frame.h @@ -18,26 +18,6 @@ #include "game_list_utils.h" #include "gui_context_menus.h" -namespace GameListFrameHelper { - -/** - * Helper function to perform a case-insensitive comparison of two strings. - * This function converts both strings to lowercase and then compares them. - * - * @param a First string for comparison. - * @param b Second string for comparison. - * @return true if a < b, false otherwise. - */ -inline bool CompareStringsCaseInsensitive(const std::string& a, const std::string& b) { - std::string lower_a = a; - std::string lower_b = b; - std::transform(lower_a.begin(), lower_a.end(), lower_a.begin(), ::tolower); - std::transform(lower_b.begin(), lower_b.end(), lower_b.begin(), ::tolower); - return lower_a < lower_b; -} - -} // namespace GameListFrameHelper - class GameListFrame : public QTableWidget { Q_OBJECT public: @@ -93,7 +73,7 @@ public: static bool CompareStringsAscending(GameInfo a, GameInfo b, int columnIndex) { switch (columnIndex) { case 1: { - return GameListFrameHelper::CompareStringsCaseInsensitive(a.name, b.name); + return CompareStringsCaseInsensitive(a.name, b.name); } case 2: return a.compatibility.status < b.compatibility.status; @@ -119,7 +99,7 @@ public: static bool CompareStringsDescending(GameInfo a, GameInfo b, int columnIndex) { switch (columnIndex) { case 1: { - return GameListFrameHelper::CompareStringsCaseInsensitive(a.name, b.name); + return CompareStringsCaseInsensitive(b.name, a.name); } case 2: return a.compatibility.status > b.compatibility.status; @@ -141,4 +121,10 @@ public: return false; } } + + static bool CompareStringsCaseInsensitive(std::string_view a, std::string_view b) { + auto lhs = a | std::views::transform(::tolower); + auto rhs = b | std::views::transform(::tolower); + return std::ranges::lexicographical_compare(lhs, rhs); + } };