Merge branch 'localization' of https://github.com/coelckers/gzdoom into localization

This commit is contained in:
Christoph Oelckers 2019-02-15 10:20:14 +01:00
commit 9fba9eee18
32 changed files with 327 additions and 231 deletions

View file

@ -1251,6 +1251,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