Updated single_include to support mbstowcs_s Windows impl

This commit is contained in:
Pranav Srinivas Kumar
2023-02-15 07:11:53 -08:00
parent 11c60675d5
commit bfe95fee17

View File

@@ -1649,6 +1649,20 @@ static inline int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) {
}
// convert UTF-8 string to wstring
#ifdef _MSC_VER
static inline std::wstring utf8_decode(const std::string& s) {
std::string curLocale = setlocale(LC_ALL, "");
const char* _Source = s.c_str();
size_t _Dsize = std::strlen(_Source) + 1;
wchar_t* _Dest = new wchar_t[_Dsize];
size_t _Osize;
mbstowcs_s(&_Osize, _Dest, _Dsize, _Source, _Dsize);
std::wstring result = _Dest;
delete[] _Dest;
setlocale(LC_ALL, curLocale.c_str());
return result;
}
#else
static inline std::wstring utf8_decode(const std::string& s) {
std::string curLocale = setlocale(LC_ALL, "");
const char* _Source = s.c_str();
@@ -1661,6 +1675,7 @@ static inline std::wstring utf8_decode(const std::string &s) {
setlocale(LC_ALL, curLocale.c_str());
return result;
}
#endif
} // namespace details