Merge pull request 'Fix utf8 conversion' (#115) from fix/utf8-conversion into release/v8.3.0

This commit is contained in:
Maxim Kadushkin
2024-12-10 13:25:49 +00:00
3 changed files with 8 additions and 14 deletions

View File

@ -4,6 +4,7 @@
#include "resource.h"
#include "utils.h"
#include <Windows.h>
#include <codecvt>
#include <cwctype>
#include <algorithm>
#include <sstream>
@ -45,10 +46,8 @@ wstring getPrimaryLang(const wstring &lang, bool withScript = false)
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);
}
TranslationsMap Translator::translMap = TranslationsMap();

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