From 32735428bbc69cf23b0dd05150cd3eb48c1d461a Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 1 Jul 2016 17:14:34 +0100 Subject: [PATCH 1/2] More SGPath APIs --- simgear/misc/sg_path.cxx | 19 +++++++++++++++++++ simgear/misc/sg_path.hxx | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index efdf8438..067abff6 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -374,6 +374,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 { @@ -871,6 +876,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; diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 9dc48458..0fbdf441 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -268,6 +268,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 +317,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); From cf18d4eaafbfb8c45acd80efd81e5171d1d9f035 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 2 Jul 2016 09:34:27 +0100 Subject: [PATCH 2/2] SGPath can convert to std::wstring --- simgear/misc/sg_path.cxx | 20 ++++++++++++++++++++ simgear/misc/sg_path.hxx | 1 + 2 files changed, 21 insertions(+) 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