Using decltype() and removing +1/-1 "dance"

This commit is contained in:
Nathan Woods 2016-07-25 07:57:54 -04:00
parent 4a9e9742fd
commit 23175a3091
2 changed files with 4 additions and 7 deletions

View File

@ -207,11 +207,8 @@ osd_file::error osd_file::open(std::string const &orig_path, UINT32 openflags, p
// create the path if necessary
if ((ERROR_PATH_NOT_FOUND == err) && (openflags & OPEN_FLAG_CREATE) && (openflags & OPEN_FLAG_CREATE_PATHS))
{
// the code below assumes these are the same
assert(std::string::npos == std::wstring::npos);
auto pathsep = t_path.rfind('\\');
if (pathsep != std::string::npos)
if (pathsep != decltype(t_path)::npos)
{
// create the path up to the file
t_path[pathsep] = 0;

View File

@ -25,9 +25,9 @@ std::string &astring_from_utf8(std::string &dst, const char *s)
std::basic_string<WCHAR> wstring = wstring_from_utf8(s);
// convert UTF-16 to "ANSI code page" string
int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size() + 1, nullptr, 0, nullptr, nullptr);
dst.resize(char_count - 1);
WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size() + 1, &dst[0], char_count - 1, nullptr, nullptr);
int char_count = WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size(), nullptr, 0, nullptr, nullptr);
dst.resize(char_count);
WideCharToMultiByte(CP_ACP, 0, wstring.c_str(), wstring.size(), &dst[0], char_count, nullptr, nullptr);
return dst;
}