From 324f989be82212ee37cbca8b7346c9e46def413f Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 27 Aug 2022 11:22:33 -0400 Subject: [PATCH] inifile.cpp, miscmenu.cpp: Use std::collate for filename sorting --- src/frontend/mame/ui/inifile.cpp | 27 +++++++++++++++++++++++++-- src/frontend/mame/ui/miscmenu.cpp | 12 +++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/frontend/mame/ui/inifile.cpp b/src/frontend/mame/ui/inifile.cpp index 6cf9886324d..4475210db74 100644 --- a/src/frontend/mame/ui/inifile.cpp +++ b/src/frontend/mame/ui/inifile.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace { @@ -56,7 +57,17 @@ inifile_manager::inifile_manager(ui_options &options) } } } - std::stable_sort(m_ini_index.begin(), m_ini_index.end(), [] (auto const &x, auto const &y) { return 0 > core_stricmp(x.first.c_str(), y.first.c_str()); }); + std::collate const &coll = std::use_facet>(std::locale()); + std::stable_sort( + m_ini_index.begin(), + m_ini_index.end(), + [&coll] (auto const &x, auto const &y) + { + std::wstring const wx = wstring_from_utf8(x.first); + std::wstring const wy = wstring_from_utf8(y.first); + return 0 > coll.compare(wx.data(), wx.data() + wx.size(), wy.data(), wy.data() + wy.size()); + } + ); } //------------------------------------------------- @@ -118,9 +129,21 @@ void inifile_manager::init_category(std::string &&filename, util::core_file &fil } } } - std::stable_sort(index.begin(), index.end(), [] (auto const &x, auto const &y) { return 0 > core_stricmp(x.first.c_str(), y.first.c_str()); }); if (!index.empty()) + { + std::collate const &coll = std::use_facet>(std::locale()); + std::stable_sort( + index.begin(), + index.end(), + [&coll] (auto const &x, auto const &y) + { + std::wstring const wx = wstring_from_utf8(x.first); + std::wstring const wy = wstring_from_utf8(y.first); + return 0 > coll.compare(wx.data(), wx.data() + wx.size(), wy.data(), wy.data() + wy.size()); + } + ); m_ini_index.emplace_back(std::move(filename), std::move(index)); + } } diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index 55a2aab986f..b621581ee89 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -28,12 +28,11 @@ #include "romload.h" #include "uiinput.h" -#include "corestr.h" - #include #include #include #include +#include namespace ui { @@ -445,10 +444,17 @@ void menu_crosshair::populate(float &customtop, float &custombottom) if ((length > 4) && core_filename_ends_with(dir->name, ".png")) m_pics.emplace_back(dir->name, length - 4); } + std::collate const &coll = std::use_facet>(std::locale()); std::stable_sort( m_pics.begin(), m_pics.end(), - [] (std::string const &a, std::string const &b) { return 0 > core_stricmp(a.c_str(), b.c_str()); }); + [&coll] (auto const &x, auto const &y) + { + std::wstring const wx = wstring_from_utf8(x); + std::wstring const wy = wstring_from_utf8(y); + return 0 > coll.compare(wx.data(), wx.data() + wx.size(), wy.data(), wy.data() + wy.size()); + } + ); } // Make sure to keep these matched to the CROSSHAIR_VISIBILITY_xxx types