diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index e28af592..bc0fc450 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef _WIN32 # include @@ -374,6 +375,11 @@ string SGPath::dir() const { } } +SGPath SGPath::dirPath() const +{ + return SGPath::fromUtf8(dir()); +} + // get the base part of the path (everything but the extension.) string SGPath::base() const { @@ -872,6 +878,20 @@ std::vector SGPath::pathsFromEnv(const char *name) //------------------------------------------------------------------------------ +std::vector SGPath::pathsFromUtf8(const std::string& paths) +{ + std::vector r; + string_list items = sgPathSplit(paths); + string_list_iterator it; + for (it = items.begin(); it != items.end(); ++it) { + r.push_back(SGPath::fromUtf8(it->c_str())); + } + + return r; +} + +//------------------------------------------------------------------------------ + std::vector SGPath::pathsFromLocal8Bit(const std::string& paths) { std::vector r; @@ -962,3 +982,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 9dc48458..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 @@ -268,6 +269,12 @@ public: * or if the destination already exists, or is not writeable */ bool rename(const SGPath& newName); + + + /** + * return the path of the parent directory of this path. + */ + SGPath dirPath() const; enum StandardLocation { @@ -311,6 +318,8 @@ public: static std::vector pathsFromEnv(const char* name); + static std::vector pathsFromUtf8(const std::string& paths); + static std::vector pathsFromLocal8Bit(const std::string& paths); static std::string join(const std::vector& paths, const std::string& joinWith);