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:
parent
532ebf1798
commit
5bb7beb379
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user