Skip to content

Commit

Permalink
[win] updatesvc: fix utf8 to utf16 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplestStudio committed Dec 10, 2024
1 parent 315cdf8 commit 2ed7586
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 2 additions & 6 deletions win-linux/extras/update-daemon/src/classes/cjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions win-linux/extras/update-daemon/src/classes/translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2ed7586

Please sign in to comment.