mirror of
https://github.com/holub/mame
synced 2025-07-06 10:29:38 +03:00
frontend: Fixed clone sorting; osd/strconv.cpp: The string_view treatment, and fixed a bug with to/from ANSI codepage.
This commit is contained in:
parent
38082ccbee
commit
30dad180dd
@ -182,8 +182,11 @@ private:
|
|||||||
// populate parent descriptions while still ordered by shortname
|
// populate parent descriptions while still ordered by shortname
|
||||||
populate_parents();
|
populate_parents();
|
||||||
|
|
||||||
|
// get rid of the "empty" driver - we don't need positions to line up any more
|
||||||
|
m_sorted_list.erase(m_sorted_list.begin() + driver_list::find(GAME_NAME(___empty)));
|
||||||
|
|
||||||
// sort drivers and notify
|
// sort drivers and notify
|
||||||
std::collate<wchar_t> const &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
|
std::collate<wchar_t> const &coll = std::use_facet<std::collate<wchar_t> >(std::locale());
|
||||||
auto const compare_names =
|
auto const compare_names =
|
||||||
[&coll] (std::string const &x, std::string const &y) -> bool
|
[&coll] (std::string const &x, std::string const &y) -> bool
|
||||||
{
|
{
|
||||||
@ -307,12 +310,12 @@ private:
|
|||||||
for (int x = 0; x < driver_list::total(); ++x)
|
for (int x = 0; x < driver_list::total(); ++x)
|
||||||
{
|
{
|
||||||
game_driver const &driver(driver_list::driver(x));
|
game_driver const &driver(driver_list::driver(x));
|
||||||
|
ui_system_info &ins(m_sorted_list.emplace_back(driver, x, false));
|
||||||
if (&driver != &GAME_NAME(___empty))
|
if (&driver != &GAME_NAME(___empty))
|
||||||
{
|
{
|
||||||
if (driver.flags & machine_flags::IS_BIOS_ROOT)
|
if (driver.flags & machine_flags::IS_BIOS_ROOT)
|
||||||
++m_bios_count;
|
++m_bios_count;
|
||||||
|
|
||||||
ui_system_info &ins(m_sorted_list.emplace_back(driver, x, false));
|
|
||||||
if (copydesc)
|
if (copydesc)
|
||||||
ins.description = driver.type.fullname();
|
ins.description = driver.type.fullname();
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sort array
|
// sort array
|
||||||
std::collate<wchar_t> const &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
|
std::collate<wchar_t> const &coll = std::use_facet<std::collate<wchar_t> >(std::locale());
|
||||||
auto const compare_names =
|
auto const compare_names =
|
||||||
[&coll] (std::string const &x, std::string const &y) -> bool
|
[&coll] (std::string const &x, std::string const &y) -> bool
|
||||||
{
|
{
|
||||||
|
@ -15,44 +15,18 @@
|
|||||||
|
|
||||||
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS) || defined(OSD_UWP)
|
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS) || defined(OSD_UWP)
|
||||||
|
|
||||||
namespace
|
namespace osd::text {
|
||||||
{
|
|
||||||
// class designed to provide inputs to WideCharToMultiByte() and MultiByteToWideChar()
|
|
||||||
template<typename T>
|
|
||||||
class string_source
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
string_source(const T *str) : m_str(str), m_char_count(-1)
|
|
||||||
{
|
|
||||||
assert(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
string_source(const std::basic_string<T> &str) : m_str(str.c_str()), m_char_count((int)str.size() + 1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const T *string() const { return m_str; }; // returns pointer to actual characters
|
|
||||||
int char_count() const { return m_char_count; } // returns the character count (including NUL terminater), or -1 if NUL terminated
|
|
||||||
|
|
||||||
private:
|
|
||||||
const T *m_str;
|
|
||||||
int m_char_count;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace osd {
|
|
||||||
namespace text {
|
|
||||||
|
|
||||||
//============================================================
|
//============================================================
|
||||||
// mbstring_from_wstring
|
// mbstring_from_wstring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
static std::string &mbstring_from_wstring(std::string &dst, UINT code_page, const string_source<wchar_t> &src)
|
inline std::string &mbstring_from_wstring(std::string &dst, UINT code_page, const std::wstring_view &src)
|
||||||
{
|
{
|
||||||
// convert UTF-16 to the specified code page
|
// convert UTF-16 to the specified code page
|
||||||
int dst_char_count = WideCharToMultiByte(code_page, 0, src.string(), src.char_count(), nullptr, 0, nullptr, nullptr);
|
const int dst_char_count = WideCharToMultiByte(code_page, 0, src.data(), src.length(), nullptr, 0, nullptr, nullptr);
|
||||||
dst.resize(dst_char_count - 1);
|
dst.resize(dst_char_count);
|
||||||
WideCharToMultiByte(code_page, 0, src.string(), src.char_count(), &dst[0], dst_char_count, nullptr, nullptr);
|
WideCharToMultiByte(code_page, 0, &src[0], src.length(), dst.data(), dst_char_count, nullptr, nullptr);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
@ -62,12 +36,12 @@ static std::string &mbstring_from_wstring(std::string &dst, UINT code_page, cons
|
|||||||
// wstring_from_mbstring
|
// wstring_from_mbstring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
static std::wstring &wstring_from_mbstring(std::wstring &dst, const string_source<char> &src, UINT code_page)
|
inline std::wstring &wstring_from_mbstring(std::wstring &dst, const std::string_view &src, UINT code_page)
|
||||||
{
|
{
|
||||||
// convert multibyte string (in specified code page) to UTF-16
|
// convert multibyte string (in specified code page) to UTF-16
|
||||||
int dst_char_count = MultiByteToWideChar(code_page, 0, src.string(), src.char_count(), nullptr, 0);
|
const int dst_char_count = MultiByteToWideChar(code_page, 0, src.data(), src.length(), nullptr, 0);
|
||||||
dst.resize(dst_char_count - 1);
|
dst.resize(dst_char_count);
|
||||||
MultiByteToWideChar(CP_UTF8, 0, src.string(), src.char_count(), &dst[0], dst_char_count - 1);
|
MultiByteToWideChar(code_page, 0, &src[0], src.length(), dst.data(), dst_char_count);
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
@ -77,13 +51,13 @@ static std::wstring &wstring_from_mbstring(std::wstring &dst, const string_sourc
|
|||||||
// to_astring
|
// to_astring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::string &to_astring(std::string &dst, const std::string &s)
|
std::string &to_astring(std::string &dst, std::string_view s)
|
||||||
{
|
{
|
||||||
// convert MAME string (UTF-8) to UTF-16
|
// convert MAME string (UTF-8) to UTF-16
|
||||||
std::wstring wstring = to_wstring(s);
|
std::wstring wstring = to_wstring(s);
|
||||||
|
|
||||||
// convert UTF-16 to "ANSI code page" string
|
// convert UTF-16 to "ANSI code page" string
|
||||||
return mbstring_from_wstring(dst, CP_ACP, string_source<wchar_t>(wstring));
|
return mbstring_from_wstring(dst, CP_ACP, wstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -98,7 +72,7 @@ std::string &to_astring(std::string &dst, const char *s)
|
|||||||
std::wstring wstring = to_wstring(s);
|
std::wstring wstring = to_wstring(s);
|
||||||
|
|
||||||
// convert UTF-16 to "ANSI code page" string
|
// convert UTF-16 to "ANSI code page" string
|
||||||
return mbstring_from_wstring(dst, CP_ACP, string_source<wchar_t>(wstring));
|
return mbstring_from_wstring(dst, CP_ACP, wstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +80,7 @@ std::string &to_astring(std::string &dst, const char *s)
|
|||||||
// to_astring
|
// to_astring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::string to_astring(const std::string &s)
|
std::string to_astring(std::string_view s)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
to_astring(result, s);
|
to_astring(result, s);
|
||||||
@ -130,11 +104,11 @@ std::string to_astring(const char *s)
|
|||||||
// from_astring
|
// from_astring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::string &from_astring(std::string &dst, const std::string &s)
|
std::string &from_astring(std::string &dst, std::string_view s)
|
||||||
{
|
{
|
||||||
// convert "ANSI code page" string to UTF-16
|
// convert "ANSI code page" string to UTF-16
|
||||||
std::wstring wstring;
|
std::wstring wstring;
|
||||||
wstring_from_mbstring(wstring, string_source<char>(s), CP_ACP);
|
wstring_from_mbstring(wstring, s, CP_ACP);
|
||||||
|
|
||||||
// convert UTF-16 to MAME string (UTF-8)
|
// convert UTF-16 to MAME string (UTF-8)
|
||||||
return from_wstring(dst, wstring);
|
return from_wstring(dst, wstring);
|
||||||
@ -149,7 +123,7 @@ std::string &from_astring(std::string &dst, const CHAR *s)
|
|||||||
{
|
{
|
||||||
// convert "ANSI code page" string to UTF-16
|
// convert "ANSI code page" string to UTF-16
|
||||||
std::wstring wstring;
|
std::wstring wstring;
|
||||||
wstring_from_mbstring(wstring, string_source<char>(s), CP_ACP);
|
wstring_from_mbstring(wstring, s, CP_ACP);
|
||||||
|
|
||||||
// convert UTF-16 to MAME string (UTF-8)
|
// convert UTF-16 to MAME string (UTF-8)
|
||||||
return from_wstring(dst, wstring);
|
return from_wstring(dst, wstring);
|
||||||
@ -160,7 +134,7 @@ std::string &from_astring(std::string &dst, const CHAR *s)
|
|||||||
// from_astring
|
// from_astring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::string from_astring(const std::string &s)
|
std::string from_astring(std::string_view s)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
from_astring(result, s);
|
from_astring(result, s);
|
||||||
@ -184,10 +158,10 @@ std::string from_astring(const CHAR *s)
|
|||||||
// to_wstring
|
// to_wstring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::wstring &to_wstring(std::wstring &dst, const std::string &s)
|
std::wstring &to_wstring(std::wstring &dst, std::string_view s)
|
||||||
{
|
{
|
||||||
// convert MAME string (UTF-8) to UTF-16
|
// convert MAME string (UTF-8) to UTF-16
|
||||||
return wstring_from_mbstring(dst, string_source<char>(s), CP_UTF8);
|
return wstring_from_mbstring(dst, s, CP_UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -198,7 +172,7 @@ std::wstring &to_wstring(std::wstring &dst, const std::string &s)
|
|||||||
std::wstring &to_wstring(std::wstring &dst, const char *s)
|
std::wstring &to_wstring(std::wstring &dst, const char *s)
|
||||||
{
|
{
|
||||||
// convert MAME string (UTF-8) to UTF-16
|
// convert MAME string (UTF-8) to UTF-16
|
||||||
return wstring_from_mbstring(dst, string_source<char>(s), CP_UTF8);
|
return wstring_from_mbstring(dst, s, CP_UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -206,7 +180,7 @@ std::wstring &to_wstring(std::wstring &dst, const char *s)
|
|||||||
// to_wstring
|
// to_wstring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::wstring to_wstring(const std::string &s)
|
std::wstring to_wstring(std::string_view s)
|
||||||
{
|
{
|
||||||
std::wstring result;
|
std::wstring result;
|
||||||
to_wstring(result, s);
|
to_wstring(result, s);
|
||||||
@ -230,10 +204,10 @@ std::wstring to_wstring(const char *s)
|
|||||||
// from_wstring
|
// from_wstring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::string &from_wstring(std::string &dst, const std::wstring &s)
|
std::string &from_wstring(std::string &dst, std::wstring_view s)
|
||||||
{
|
{
|
||||||
// convert UTF-16 to MAME string (UTF-8)
|
// convert UTF-16 to MAME string (UTF-8)
|
||||||
return mbstring_from_wstring(dst, CP_UTF8, string_source<wchar_t>(s));
|
return mbstring_from_wstring(dst, CP_UTF8, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -244,7 +218,7 @@ std::string &from_wstring(std::string &dst, const std::wstring &s)
|
|||||||
std::string &from_wstring(std::string &dst, const WCHAR *s)
|
std::string &from_wstring(std::string &dst, const WCHAR *s)
|
||||||
{
|
{
|
||||||
// convert UTF-16 to MAME string (UTF-8)
|
// convert UTF-16 to MAME string (UTF-8)
|
||||||
return mbstring_from_wstring(dst, CP_UTF8, string_source<wchar_t>(s));
|
return mbstring_from_wstring(dst, CP_UTF8, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -252,7 +226,7 @@ std::string &from_wstring(std::string &dst, const WCHAR *s)
|
|||||||
// from_wstring
|
// from_wstring
|
||||||
//============================================================
|
//============================================================
|
||||||
|
|
||||||
std::string from_wstring(const std::wstring &s)
|
std::string from_wstring(std::wstring_view s)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
from_wstring(result, s);
|
from_wstring(result, s);
|
||||||
@ -271,8 +245,7 @@ std::string from_wstring(const WCHAR *s)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace text
|
} // namespace osd::text
|
||||||
}; // namespace osd
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================
|
//============================================================
|
||||||
|
@ -19,29 +19,29 @@
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
namespace osd
|
namespace osd::text {
|
||||||
{
|
|
||||||
namespace text
|
|
||||||
{
|
|
||||||
std::string to_astring(const std::string &s);
|
|
||||||
std::string to_astring(const char *s);
|
|
||||||
std::string &to_astring(std::string &dst, const std::string &s);
|
|
||||||
std::string &to_astring(std::string &dst, const char *s);
|
|
||||||
std::string from_astring(const std::string &s);
|
|
||||||
std::string from_astring(const CHAR *s);
|
|
||||||
std::string &from_astring(std::string &dst, const std::string &s);
|
|
||||||
std::string &from_astring(std::string &dst, const CHAR *s);
|
|
||||||
|
|
||||||
std::wstring to_wstring(const std::string &s);
|
std::string to_astring(std::string_view s);
|
||||||
std::wstring to_wstring(const char *s);
|
std::string to_astring(const char *s);
|
||||||
std::wstring &to_wstring(std::wstring &dst, const std::string &s);
|
std::string &to_astring(std::string &dst, std::string_view s);
|
||||||
std::wstring &to_wstring(std::wstring &dst, const char *s);
|
std::string &to_astring(std::string &dst, const char *s);
|
||||||
std::string from_wstring(const std::wstring &s);
|
std::string from_astring(const std::string_view s);
|
||||||
std::string from_wstring(const WCHAR *s);
|
std::string from_astring(const CHAR *s);
|
||||||
std::string &from_wstring(std::string &dst, const std::wstring &s);
|
std::string &from_astring(std::string &dst, std::string_view s);
|
||||||
std::string &from_wstring(std::string &dst, const WCHAR *s);
|
std::string &from_astring(std::string &dst, const CHAR *s);
|
||||||
|
|
||||||
|
std::wstring to_wstring(std::string_view s);
|
||||||
|
std::wstring to_wstring(const char *s);
|
||||||
|
std::wstring &to_wstring(std::wstring &dst, std::string_view s);
|
||||||
|
std::wstring &to_wstring(std::wstring &dst, const char *s);
|
||||||
|
std::string from_wstring(const std::wstring_view s);
|
||||||
|
std::string from_wstring(const WCHAR *s);
|
||||||
|
std::string &from_wstring(std::string &dst, std::wstring_view s);
|
||||||
|
std::string &from_wstring(std::string &dst, const WCHAR *s);
|
||||||
|
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
typedef std::wstring tstring;
|
typedef std::wstring tstring;
|
||||||
@ -53,8 +53,7 @@ typedef std::string tstring;
|
|||||||
#define from_tstring from_astring
|
#define from_tstring from_astring
|
||||||
#endif // UNICODE
|
#endif // UNICODE
|
||||||
|
|
||||||
}
|
} // namespace osd::text
|
||||||
}
|
|
||||||
|
|
||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user