mirror of
https://github.com/wiiu-env/ftpiiu_plugin.git
synced 2024-12-28 05:11:48 +01:00
Fix path building
This commit is contained in:
parent
9f5bf0b042
commit
bae8254d22
@ -234,15 +234,26 @@ std::string resolvePath (std::string_view const path_)
|
||||
/// \param args_ Child component
|
||||
std::string buildPath (std::string_view const cwd_, std::string_view const args_)
|
||||
{
|
||||
std::string path;
|
||||
|
||||
// absolute path
|
||||
if (args_[0] == '/')
|
||||
return std::string (args_);
|
||||
path = std::string (args_);
|
||||
// relative path
|
||||
else
|
||||
path = std::string (cwd_) + '/' + std::string (args_);
|
||||
|
||||
// root directory
|
||||
if (cwd_.size () == 1)
|
||||
return std::string (cwd_) + std::string (args_);
|
||||
// coalesce consecutive slashes
|
||||
auto it = std::begin (path);
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user