0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-20 12:12:15 +02:00

wstring.hpp: workaround for mingw's codecvt_utf8 bug

mingw produces incorrect result when converting
from utf8 to wchar_t using codecvt_utf8.

https://sourceforge.net/p/mingw-w64/bugs/538/
Signed-off-by: Lev Stipakov <lev@openvpn.net>
This commit is contained in:
Lev Stipakov 2020-02-26 11:09:14 +02:00 committed by David Sommerseth
parent 532ebf1798
commit 5bb7beb379
No known key found for this signature in database
GPG Key ID: 86CF944C9671FDF2

View File

@ -33,14 +33,23 @@ namespace openvpn {
inline std::wstring from_utf8(const std::string& str)
{
#ifdef __MINGW32__
// https://sourceforge.net/p/mingw-w64/bugs/538/
typedef std::codecvt_utf8<wchar_t, 0x10ffff, std::little_endian> cvt_type;
#else
typedef std::codecvt_utf8<wchar_t> cvt_type;
#endif
std::wstring_convert<cvt_type, wchar_t> cvt;
return cvt.from_bytes(str);
}
inline std::string to_utf8(const std::wstring& wstr)
{
#ifdef __MINGW32__
typedef std::codecvt_utf8<wchar_t, 0x10ffff, std::little_endian> cvt_type;
#else
typedef std::codecvt_utf8<wchar_t> cvt_type;
#endif
std::wstring_convert<cvt_type, wchar_t> cvt;
return cvt.to_bytes(wstr);
}