mirror of
https://github.com/p-ranav/indicators.git
synced 2025-12-16 04:18:51 +08:00
Added preprocesser fork to account for missing mbstowcs_s on linux
This commit is contained in:
@@ -309,10 +309,11 @@ static inline int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert UTF-8 string to wstring
|
// convert UTF-8 string to wstring
|
||||||
|
#ifdef _MSC_VER
|
||||||
static inline std::wstring utf8_decode(const std::string& s) {
|
static inline std::wstring utf8_decode(const std::string& s) {
|
||||||
std::string curLocale = setlocale(LC_ALL, "");
|
std::string curLocale = setlocale(LC_ALL, "");
|
||||||
const char* _Source = s.c_str();
|
const char* _Source = s.c_str();
|
||||||
size_t _Dsize = strlen(_Source) + 1;
|
size_t _Dsize = std::strlen(_Source) + 1;
|
||||||
wchar_t* _Dest = new wchar_t[_Dsize];
|
wchar_t* _Dest = new wchar_t[_Dsize];
|
||||||
size_t _Osize;
|
size_t _Osize;
|
||||||
mbstowcs_s(&_Osize, _Dest, _Dsize, _Source, _Dsize);
|
mbstowcs_s(&_Osize, _Dest, _Dsize, _Source, _Dsize);
|
||||||
@@ -321,6 +322,20 @@ static inline std::wstring utf8_decode(const std::string &s) {
|
|||||||
setlocale(LC_ALL, curLocale.c_str());
|
setlocale(LC_ALL, curLocale.c_str());
|
||||||
return result;
|
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();
|
||||||
|
size_t _Dsize = mbstowcs(NULL, _Source, 0) + 1;
|
||||||
|
wchar_t* _Dest = new wchar_t[_Dsize];
|
||||||
|
wmemset(_Dest, 0, _Dsize);
|
||||||
|
mbstowcs(_Dest, _Source, _Dsize);
|
||||||
|
std::wstring result = _Dest;
|
||||||
|
delete[] _Dest;
|
||||||
|
setlocale(LC_ALL, curLocale.c_str());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user