- switched the Windows backend to use the Windows Unicode API.

With localization for non-Latin languages on the support list the multibyte API doesn't cut it anymore. It neither can handle system text output outside the local code page nor can an ANSI window receive text input outside its own code page.
Similar problems exist for file names. With the multibyte API it is impossible to handle any file containing characters outside the active local code page.

So as of now, everything that may pass along some Unicode text will use the Unicode API with some text conversion functions. The only places where calls to the multibyte API were left are those where known string literals are passed or where the information is not used for anything but comparing it to other return values from the same API.
This commit is contained in:
Christoph Oelckers 2019-02-14 22:22:15 +01:00
commit 868ac5adf8
30 changed files with 325 additions and 228 deletions

View file

@ -38,6 +38,7 @@
#include <new> // for bad_alloc
#include "zstring.h"
#include "v_text.h"
FNullStringData FString::NullString =
{
@ -1231,6 +1232,51 @@ void FString::Split(TArray<FString>& tokens, const char *delimiter, EmptyTokenTy
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
// Convert from and to Windows wide strings so that we can interface with the Unicode version of the Windows API.
FString::FString(const wchar_t *copyStr)
{
if (copyStr == NULL || *copyStr == '\0')
{
ResetToNull();
}
else
{
auto len = wcslen(copyStr);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, copyStr, (int)len, nullptr, 0, nullptr, nullptr);
AllocBuffer(size_needed);
WideCharToMultiByte(CP_UTF8, 0, copyStr, (int)len, Chars, size_needed, nullptr, nullptr);
}
}
FString &FString::operator=(const wchar_t *copyStr)
{
if (copyStr == NULL || *copyStr == '\0')
{
Data()->Release();
ResetToNull();
}
else
{
auto len = wcslen(copyStr);
int size_needed = WideCharToMultiByte(CP_UTF8, 0, copyStr, (int)len, nullptr, 0, nullptr, nullptr);
ReallocBuffer(size_needed);
WideCharToMultiByte(CP_UTF8, 0, copyStr, (int)len, Chars, size_needed, nullptr, nullptr);
}
return *this;
}
std::wstring WideString(const char *cin)
{
const uint8_t *in = (const uint8_t*)cin;
// This is a bit tricky because we need to support both UTF-8 and legacy content in ISO-8859-1
// and thanks to user-side string manipulation it can be that a text mixes both.
// To convert the string this uses the same function as all text printing in the engine.
TArray<wchar_t> buildbuffer;
while (*in) buildbuffer.Push((wchar_t)GetCharFromString(in));
buildbuffer.Push(0);
return std::wstring(buildbuffer.Data());
}
static HANDLE StringHeap;
const SIZE_T STRING_HEAP_SIZE = 64*1024;
#endif