- string conversion fixes

This commit is contained in:
Christoph Oelckers 2023-09-06 00:19:36 +02:00
parent 17ab6e851a
commit e7a79b0d44
3 changed files with 13 additions and 8 deletions

View file

@ -202,20 +202,26 @@ static size_t FS_GetFileSize(findstate_t* handle, const char* pathname)
std::wstring toWide(const char* str)
{
int len = (int)strlen(str);
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, nullptr, 0);
std::wstring wide;
wide.resize(size_needed);
MultiByteToWideChar(CP_UTF8, 0, str, len, &wide.front(), size_needed);
if (len > 0)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, nullptr, 0);
wide.resize(size_needed);
MultiByteToWideChar(CP_UTF8, 0, str, len, &wide.front(), size_needed);
}
return wide;
}
static std::string toUtf8(const wchar_t* str)
{
auto len = wcslen(str);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, str, (int)len, nullptr, 0, nullptr, nullptr);
std::string utf8;
utf8.resize(size_needed);
WideCharToMultiByte(CP_UTF8, 0, str, (int)len, &utf8.front(), size_needed, nullptr, nullptr);
if (len > 0)
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, str, (int)len, nullptr, 0, nullptr, nullptr);
utf8.resize(size_needed);
WideCharToMultiByte(CP_UTF8, 0, str, (int)len, &utf8.front(), size_needed, nullptr, nullptr);
}
return utf8;
}

View file

@ -45,7 +45,6 @@
#include "gl_renderstate.h"
#include "gl_samplers.h"
#include "gl_hwtexture.h"
#include "printf.h"
namespace OpenGLRenderer
{

View file

@ -413,7 +413,7 @@ int getAlternative(int code)
case 0x41e: return 'O';
case 0x420: return 'P';
case 0x421: return 'C';
case 0x423: return 'T';
case 0x422: return 'T';
case 0x425: return 'X';
case 0x430: return 'a';
case 0x435: return 'e';