[win] updatesvc: fix utf8 to utf16 conversion

This commit is contained in:
SimplestStudio
2024-12-10 13:16:52 +02:00
parent 315cdf8849
commit 2ed7586098
2 changed files with 5 additions and 10 deletions

View File

@ -99,12 +99,8 @@ tstring JsonValue::toTString()
if (pimpl->val && pimpl->val->type == json_type_string) {
json_string_s *jstr = (json_string_s*)pimpl->val->payload;
#ifdef _WIN32
size_t len = jstr->string_size, outSize = 0;
wchar_t *pDestBuf = new wchar_t[len + 1];
mbstowcs_s(&outSize, pDestBuf, len + 1, jstr->string, len);
if (outSize > 0)
str = pDestBuf;
delete[] pDestBuf;
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
str = converter.from_bytes(std::string(jstr->string, jstr->string_size));
#else
str = std::string(jstr->string, jstr->string_size);
#endif

View File

@ -4,6 +4,7 @@
# include "platform_win/resource.h"
# include "platform_win/utils.h"
# include <Windows.h>
# include <codecvt>
# include <cwctype>
# define istalnum(c) std::iswalnum(c)
# define istalpha(c) std::iswalpha(c)
@ -55,10 +56,8 @@ tstring getPrimaryLang(const tstring &lang, bool withScript = false)
#ifdef _WIN32
wstring StrToWStr(const string &str)
{
size_t len = str.length(), outSize = 0;
wstring wstr(len, '\0');
mbstowcs_s(&outSize, &wstr[0], len + 1, str.c_str(), len);
return wstr.c_str();
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
return converter.from_bytes(str);
}
#endif