From: James Turner Date: Sat, 2 Jul 2016 08:34:27 +0000 (+0100) Subject: SGPath can convert to std::wstring X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9b881acc60f9c0032622972291981ccb93c37fe3;p=simgear.git SGPath can convert to std::wstring --- diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 067abff6..1e6836c3 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef _WIN32 # include @@ -980,3 +981,22 @@ std::string SGPath::join(const std::vector& paths, const std::string& jo return r; } + +//------------------------------------------------------------------------------ +std::wstring SGPath::wstr() const +{ +#ifdef SG_WINDOWS + return std::wstring(); +#else + wchar_t wideBuf[2048]; + size_t count = mbstowcs(wideBuf, path.c_str(), 2048); + if (count == -1) { + return std::wstring(); + } else if (count == 2048) { + SG_LOG( SG_GENERAL, SG_ALERT, "SGPath::wstr: overflowed conversion buffer for " << *this ); + } + + return std::wstring(wideBuf, count); +#endif +} + diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 0fbdf441..815960d7 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -190,6 +190,7 @@ public: std::string local8BitStr() const; + std::wstring wstr() const; /** * Get the path string