2022-11-22 01:33:22 +08:00
|
|
|
#include "unicode.h"
|
|
|
|
|
|
2023-03-24 23:21:39 +08:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
2022-11-26 12:52:04 +08:00
|
|
|
void ffStrbufSetNWS(FFstrbuf* result, uint32_t length, const wchar_t* source)
|
2022-11-22 01:33:22 +08:00
|
|
|
{
|
2022-11-26 12:52:04 +08:00
|
|
|
if(!length)
|
2022-11-22 01:33:22 +08:00
|
|
|
{
|
|
|
|
|
ffStrbufClear(result);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-26 12:52:04 +08:00
|
|
|
int size_needed = WideCharToMultiByte(CP_UTF8, 0, source, (int)length, NULL, 0, NULL, NULL);
|
2025-12-08 20:11:14 +08:00
|
|
|
if (size_needed <= 0)
|
2022-11-23 15:42:19 +08:00
|
|
|
{
|
2025-04-01 16:37:26 +08:00
|
|
|
ffStrbufSetF(result, "WCTMB failed: %u", (unsigned) GetLastError());
|
2023-05-27 22:28:40 +08:00
|
|
|
return;
|
2022-11-23 15:42:19 +08:00
|
|
|
}
|
2025-04-01 16:37:26 +08:00
|
|
|
ffStrbufEnsureFixedLengthFree(result, (uint32_t)size_needed);
|
2023-05-27 22:28:40 +08:00
|
|
|
WideCharToMultiByte(CP_UTF8, 0, source, (int)length, result->chars, size_needed, NULL, NULL);
|
|
|
|
|
result->length = (uint32_t)size_needed;
|
|
|
|
|
result->chars[size_needed] = '\0';
|
2022-11-23 15:42:19 +08:00
|
|
|
}
|
2025-12-08 20:11:14 +08:00
|
|
|
|
|
|
|
|
void ffStrbufAppendNWS(FFstrbuf* result, uint32_t length, const wchar_t* source)
|
|
|
|
|
{
|
|
|
|
|
if(!length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int size_needed = WideCharToMultiByte(CP_UTF8, 0, source, (int)length, NULL, 0, NULL, NULL);
|
|
|
|
|
if (size_needed <= 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ffStrbufEnsureFree(result, (uint32_t)size_needed);
|
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, source, (int)length, result->chars + result->length, size_needed, NULL, NULL);
|
|
|
|
|
result->length += (uint32_t)size_needed;
|
|
|
|
|
result->chars[result->length] = '\0';
|
|
|
|
|
}
|