Fix path building

This commit is contained in:
Michael Theall 2020-05-30 17:42:21 -05:00
parent 9f5bf0b042
commit bae8254d22

View File

@ -234,15 +234,26 @@ std::string resolvePath (std::string_view const path_)
/// \param args_ Child component /// \param args_ Child component
std::string buildPath (std::string_view const cwd_, std::string_view const args_) std::string buildPath (std::string_view const cwd_, std::string_view const args_)
{ {
std::string path;
// absolute path // absolute path
if (args_[0] == '/') if (args_[0] == '/')
return std::string (args_); path = std::string (args_);
// relative path
else
path = std::string (cwd_) + '/' + std::string (args_);
// root directory // coalesce consecutive slashes
if (cwd_.size () == 1) auto it = std::begin (path);
return std::string (cwd_) + std::string (args_); while (it != std::end (path))
{
if (it != std::begin (path) && *it == '/' && *std::prev (it) == '/')
it = path.erase (it);
else
++it;
}
return std::string (cwd_) + '/' + std::string (args_); return path;
} }
/// \brief Build resolved path from a parent and child /// \brief Build resolved path from a parent and child