]> git.mxchange.org Git - simgear.git/commitdiff
SGPath can convert to std::wstring
authorJames Turner <zakalawe@mac.com>
Sat, 2 Jul 2016 08:34:27 +0000 (09:34 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 13 Aug 2016 08:21:16 +0000 (10:21 +0200)
simgear/misc/sg_path.cxx
simgear/misc/sg_path.hxx

index 067abff63ab306bcf2e6e78b6eb1b3b08bf6904e..1e6836c37548bfadd7a347a987e43d4345893fe5 100644 (file)
@@ -33,6 +33,7 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <fstream>
+#include <cstdlib>
 
 #ifdef _WIN32
 #  include <direct.h>
@@ -980,3 +981,22 @@ std::string SGPath::join(const std::vector<SGPath>& 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
+}
+
index 0fbdf44161633a32ca263b8a3f8fe7640eaa0c8b..815960d7ee7acbab4889d1d18176650564b2484d 100644 (file)
@@ -190,6 +190,7 @@ public:
 
     std::string local8BitStr() const;
 
+    std::wstring wstr() const;
 
     /**
      * Get the path string