summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/frontend/mame/ui/selgame.cpp7
-rw-r--r--src/frontend/mame/ui/selsoft.cpp2
-rw-r--r--src/osd/strconv.cpp79
-rw-r--r--src/osd/strconv.h45
4 files changed, 54 insertions, 79 deletions
diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp
index 89892664fc0..12aff317f0e 100644
--- a/src/frontend/mame/ui/selgame.cpp
+++ b/src/frontend/mame/ui/selgame.cpp
@@ -182,8 +182,11 @@ private:
// populate parent descriptions while still ordered by shortname
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
- 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 =
[&coll] (std::string const &x, std::string const &y) -> bool
{
@@ -307,12 +310,12 @@ private:
for (int x = 0; x < driver_list::total(); ++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.flags & machine_flags::IS_BIOS_ROOT)
++m_bios_count;
- ui_system_info &ins(m_sorted_list.emplace_back(driver, x, false));
if (copydesc)
ins.description = driver.type.fullname();
diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp
index 8e48cbd51cb..a9d78968d64 100644
--- a/src/frontend/mame/ui/selsoft.cpp
+++ b/src/frontend/mame/ui/selsoft.cpp
@@ -218,7 +218,7 @@ public:
}
// 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 =
[&coll] (std::string const &x, std::string const &y) -> bool
{
diff --git a/src/osd/strconv.cpp b/src/osd/strconv.cpp
index 717a17d862c..6e1103adfcb 100644
--- a/src/osd/strconv.cpp
+++ b/src/osd/strconv.cpp
@@ -15,44 +15,18 @@
#if defined(SDLMAME_WIN32) || defined(OSD_WINDOWS) || defined(OSD_UWP)
-namespace
-{
- // 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 {
+namespace osd::text {
//============================================================
// 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
- int dst_char_count = WideCharToMultiByte(code_page, 0, src.string(), src.char_count(), nullptr, 0, nullptr, nullptr);
- dst.resize(dst_char_count - 1);
- WideCharToMultiByte(code_page, 0, src.string(), src.char_count(), &dst[0], dst_char_count, nullptr, nullptr);
+ const int dst_char_count = WideCharToMultiByte(code_page, 0, src.data(), src.length(), nullptr, 0, nullptr, nullptr);
+ dst.resize(dst_char_count);
+ WideCharToMultiByte(code_page, 0, &src[0], src.length(), dst.data(), dst_char_count, nullptr, nullptr);
return dst;
}
@@ -62,12 +36,12 @@ static std::string &mbstring_from_wstring(std::string &dst, UINT code_page, cons
// 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
- int dst_char_count = MultiByteToWideChar(code_page, 0, src.string(), src.char_count(), nullptr, 0);
- dst.resize(dst_char_count - 1);
- MultiByteToWideChar(CP_UTF8, 0, src.string(), src.char_count(), &dst[0], dst_char_count - 1);
+ const int dst_char_count = MultiByteToWideChar(code_page, 0, src.data(), src.length(), nullptr, 0);
+ dst.resize(dst_char_count);
+ MultiByteToWideChar(code_page, 0, &src[0], src.length(), dst.data(), dst_char_count);
return dst;
}
@@ -77,13 +51,13 @@ static std::wstring &wstring_from_mbstring(std::wstring &dst, const string_sourc
// 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
std::wstring wstring = to_wstring(s);
// 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);
// 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
//============================================================
-std::string to_astring(const std::string &s)
+std::string to_astring(std::string_view s)
{
std::string result;
to_astring(result, s);
@@ -130,11 +104,11 @@ std::string to_astring(const char *s)
// 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
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)
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
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)
return from_wstring(dst, wstring);
@@ -160,7 +134,7 @@ std::string &from_astring(std::string &dst, const CHAR *s)
// from_astring
//============================================================
-std::string from_astring(const std::string &s)
+std::string from_astring(std::string_view s)
{
std::string result;
from_astring(result, s);
@@ -184,10 +158,10 @@ std::string from_astring(const CHAR *s)
// 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
- 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)
{
// 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
//============================================================
-std::wstring to_wstring(const std::string &s)
+std::wstring to_wstring(std::string_view s)
{
std::wstring result;
to_wstring(result, s);
@@ -230,10 +204,10 @@ std::wstring to_wstring(const char *s)
// 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)
- 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)
{
// 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
//============================================================
-std::string from_wstring(const std::wstring &s)
+std::string from_wstring(std::wstring_view s)
{
std::string result;
from_wstring(result, s);
@@ -271,8 +245,7 @@ std::string from_wstring(const WCHAR *s)
return result;
}
-}; // namespace text
-}; // namespace osd
+} // namespace osd::text
//============================================================
diff --git a/src/osd/strconv.h b/src/osd/strconv.h
index 3843ee00f98..558987a167b 100644
--- a/src/osd/strconv.h
+++ b/src/osd/strconv.h
@@ -19,29 +19,29 @@
#if defined(_WIN32)
+#include <string_view>
+
#include <windows.h>
-namespace osd
-{
- 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::wstring to_wstring(const char *s);
- std::wstring &to_wstring(std::wstring &dst, const std::string &s);
- std::wstring &to_wstring(std::wstring &dst, const char *s);
- std::string from_wstring(const std::wstring &s);
- std::string from_wstring(const WCHAR *s);
- std::string &from_wstring(std::string &dst, const std::wstring &s);
- std::string &from_wstring(std::string &dst, const WCHAR *s);
+namespace osd::text {
+
+std::string to_astring(std::string_view s);
+std::string to_astring(const char *s);
+std::string &to_astring(std::string &dst, std::string_view s);
+std::string &to_astring(std::string &dst, const char *s);
+std::string from_astring(const std::string_view s);
+std::string from_astring(const CHAR *s);
+std::string &from_astring(std::string &dst, std::string_view 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
typedef std::wstring tstring;
@@ -53,8 +53,7 @@ typedef std::string tstring;
#define from_tstring from_astring
#endif // UNICODE
- }
-}
+} // namespace osd::text
#endif // defined(_WIN32)