diff --git a/SystemTools.cxx b/SystemTools.cxx index 5ca382fb7f428bf305bcc5245d96a55866f04da5..07da8dc7eef53eb70ca4a4aa4a6d6d75f6aad9e9 100644 --- a/SystemTools.cxx +++ b/SystemTools.cxx @@ -22,6 +22,7 @@ #include KWSYS_HEADER(FStream.hxx) #include KWSYS_HEADER(Encoding.hxx) +#include <algorithm> #include <fstream> #include <iostream> #include <set> @@ -3708,6 +3709,16 @@ std::string SystemTools::JoinPath( return result; } +void SystemTools::RemoveEmptyPathElements(std::vector<std::string>& path) +{ + if (path.empty()) { + return; + } + + path.erase(std::remove(path.begin() + 1, path.end(), std::string("")), + path.end()); +} + bool SystemTools::ComparePath(const std::string& c1, const std::string& c2) { #if defined(_WIN32) || defined(__APPLE__) diff --git a/SystemTools.hxx.in b/SystemTools.hxx.in index 0849e1da8feffc93045aa10497438ab00d819748..5e091c2af7ca7a8125bed687b41de873bead2632 100644 --- a/SystemTools.hxx.in +++ b/SystemTools.hxx.in @@ -474,6 +474,10 @@ public: static std::string JoinPath(std::vector<std::string>::const_iterator first, std::vector<std::string>::const_iterator last); + /** Removes empty components from path. + */ + static void RemoveEmptyPathElements(std::vector<std::string>& path); + /** * Compare a path or components of a path. */