We require C++11 now, simplify this code.

This ensures wstring to std::string conversion is always available,
needed for some HID work I’m doing on a branch,.
This commit is contained in:
James Turner 2017-10-29 13:20:39 +00:00
parent 2a60e5e338
commit 2642299d77

View File

@ -29,11 +29,8 @@
#include <cstring> // strerror_r() and strerror_s() #include <cstring> // strerror_r() and strerror_s()
#include <cctype> #include <cctype>
#include <cerrno> #include <cerrno>
#include <codecvt>
#if defined(HAVE_CPP11_CODECVT)
#include <codecvt> // new in C++11
#endif
#include "strutils.hxx" #include "strutils.hxx"
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
@ -656,26 +653,14 @@ static std::string convertWStringToMultiByte(DWORD encoding, const std::wstring&
std::wstring convertUtf8ToWString(const std::string& a) std::wstring convertUtf8ToWString(const std::string& a)
{ {
#ifdef SG_WINDOWS
return convertMultiByteToWString(CP_UTF8, a);
#elif defined(HAVE_CPP11_CODECVT)
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> ucs2conv; std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> ucs2conv;
return ucs2conv.from_bytes(a); return ucs2conv.from_bytes(a);
#else
return std::wstring();
#endif
} }
std::string convertWStringToUtf8(const std::wstring& w) std::string convertWStringToUtf8(const std::wstring& w)
{ {
#ifdef SG_WINDOWS
return convertWStringToMultiByte(CP_UTF8, w);
#elif defined(HAVE_CPP11_CODECVT)
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> ucs2conv; std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> ucs2conv;
return ucs2conv.to_bytes(w); return ucs2conv.to_bytes(w);
#else
return std::string();
#endif
} }
std::string convertWindowsLocal8BitToUtf8(const std::string& a) std::string convertWindowsLocal8BitToUtf8(const std::string& a)