From 6419668ded2506b120782d7ff7478a0d27056f21 Mon Sep 17 00:00:00 2001 From: sedenion Date: Sun, 19 Nov 2017 14:56:26 +0100 Subject: [PATCH] fix config list alphanumircal sorting function --- src/gme_game.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/gme_game.cpp b/src/gme_game.cpp index a1dcf68..993e737 100644 --- a/src/gme_game.cpp +++ b/src/gme_game.cpp @@ -26,21 +26,32 @@ int g_GameCur_Id = -1; bool GME_GameSortCfgComp(const GME_GameCfg_Struct& a_cfg, const GME_GameCfg_Struct& b_cfg) { + // convert to ASCII std::string a_title = GME_StrToMbs(a_cfg.title); std::string b_title = GME_StrToMbs(b_cfg.title); + // Convert to upper case to compare ASCII values GME_StrToUpper(a_title); GME_StrToUpper(b_title); + // test against the shorter string size_t l = a_title.size() > b_title.size() ? b_title.size() : a_title.size(); + // test for ASCII value greater than the other for(unsigned i = 0; i < l; i++) { - if(a_title[i] < b_title[i]) { - return true; - } else { - return false; + if(a_title[i] != b_title[i]) { + if(a_title[i] < b_title[i]) { + return true; + } else { + return false; + } } } + + // tested strings portions are equals, we sort by string size + if(a_title.size() < b_title.size()) + return true; + return false; }