mirror of
https://github.com/holub/mame
synced 2025-04-22 00:11:58 +03:00
inifile.cpp, miscmenu.cpp: Use std::collate for filename sorting
This commit is contained in:
parent
14e0582083
commit
324f989be8
@ -24,6 +24,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
|
||||
|
||||
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<wchar_t> const &coll = std::use_facet<std::collate<wchar_t>>(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<wchar_t> const &coll = std::use_facet<std::collate<wchar_t>>(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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,12 +28,11 @@
|
||||
#include "romload.h"
|
||||
#include "uiinput.h"
|
||||
|
||||
#include "corestr.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
|
||||
|
||||
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<wchar_t> const &coll = std::use_facet<std::collate<wchar_t>>(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
|
||||
|
Loading…
Reference in New Issue
Block a user