1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-23 03:33:35 +00:00

1. Removed usage of wcstomb_s(), which doesn't support UTF8

2. Added WideToUTF8_stupid() helper for API calls that give you byte count instead of character count of a non-null terminated UTF16 string
3. Fixed a few more places to support UTF8
This commit is contained in:
Bryan Roe
2020-04-30 16:20:37 -07:00
parent cf91d6c709
commit 10f1f53912
5 changed files with 52 additions and 17 deletions

View File

@@ -182,10 +182,21 @@ int ILibWhichPowerOfTwo(int number)
#ifdef WIN32
WCHAR ILibWideScratchPad[4096];
char ILibUTF8ScratchPad[4096];
char *ILibWideToUTF8(WCHAR* wstr, int len)
char *ILibWideToUTF8Ex(WCHAR* wstr, int len, char *buffer, int bufferLen)
{
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wstr, len, (LPSTR)ILibUTF8ScratchPad, (int)sizeof(ILibUTF8ScratchPad), NULL, NULL);
return((char*)ILibUTF8ScratchPad);
if (buffer == NULL) { buffer = ILibUTF8ScratchPad; bufferLen = (int)sizeof(ILibUTF8ScratchPad); }
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)wstr, len, (LPSTR)buffer, bufferLen, NULL, NULL);
return(buffer);
}
char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int bufferLen)
{
char *ret = NULL;
char *tmp = ILibMemory_SmartAllocate(wstrBYTESIZE + 2);
memcpy_s(tmp, wstrBYTESIZE + 2, (char*)wstr, wstrBYTESIZE);
ret = ILibWideToUTF8Ex((WCHAR*)tmp, -1, buffer, bufferLen);
ILibMemory_Free(tmp);
return(ret);
}
WCHAR* ILibUTF8ToWideEx(char* str, int len, WCHAR* buffer, int bufferCharacterSize)
{

View File

@@ -171,12 +171,17 @@ static inline void ignore_result(uintptr_t result) { (void)result; }
#endif
#ifdef WIN32
char *ILibWideToUTF8(WCHAR* wstr, int len);
char *ILibWideToUTF8Ex(WCHAR* wstr, int wstrCharacterLen, char *buffer, int bufferLen);
#define ILibWideToUTF8(wstr, wstrCharacterLen) ILibWideToUTF8Ex(wstr, wstrCharacterLen, NULL, 0)
char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int bufferLen);
#define ILibWideToUTF8_stupid(wstr, wstrBYTESIZE) ILibWideToUTF8_stupidEx(wstr, wstrBYTESIZE, NULL, 0)
WCHAR* ILibUTF8ToWideEx(char* str, int len, WCHAR* buffer, int bufferCharacterSize);
#define ILibUTF8ToWide(utf8string, len) ILibUTF8ToWideEx(utf8string, len, NULL, 0)
#else
#define ILibWideToUTF8(wstr, len) (wstr)
#define ILibWideToUTF8Ex(wstr, len, buffer, sz) (wstr)
#define ILibUTF8toWide(str, len) (str)
#define ILibUTF8ToWideEx(str, len, buffer, ccsz) (str)
#endif