Skip to content

Commit

Permalink
Merge pull request #25 from ThePhD/ziab-fixes
Browse files Browse the repository at this point in the history
Ziab fixes
  • Loading branch information
davidsiaw committed Apr 3, 2016
2 parents f567abe + c8a2c4c commit f28aea0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions LuaCppInterface/luastringconversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ std::wstring UTF8ToWStr(const std::string& utf8str)
auto original_locale = setlocale(LC_ALL, NULL);
auto loc = setlocale(LC_ALL, "en_US.UTF-8");
wchar_t* wstr_buf = new wchar_t[utf8str.size()];
#ifdef _MSC_VER
size_t converted;
mbstowcs_s(&converted, wstr_buf, utf8str.size(), utf8str.c_str(), utf8str.size());
#else
size_t converted = mbstowcs(wstr_buf, utf8str.c_str(), utf8str.size());
#endif
std::wstring result(wstr_buf);
delete[] wstr_buf;
setlocale(LC_ALL, original_locale);
Expand All @@ -25,7 +30,12 @@ std::string WStrToUTF8(const std::wstring& wstr)
auto loc = setlocale(LC_ALL, "en_US.UTF-8");
size_t max_size = wstr.size() * MAX_UTF8_CHAR_CHAIN;
char* str_buf = new char[max_size];
#ifdef _MSC_VER
size_t converted;
wcstombs_s(&converted, str_buf, max_size, wstr.c_str(), max_size);
#else
size_t converted = wcstombs(str_buf, wstr.c_str(), max_size);
#endif
std::string result(str_buf);
delete[] str_buf;
setlocale(LC_ALL, original_locale);
Expand Down

0 comments on commit f28aea0

Please sign in to comment.