From db177a0b29aaca7e7ed38eb069b30c513e9317b5 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 1 Jul 2016 17:14:34 +0100 Subject: [PATCH] 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); -- 2.39.5