Move absolutePath/sanitizePath helpers from CompilerStack to libdevcore

This commit is contained in:
Alex Beregszaszi
2018-08-06 12:54:22 +01:00
parent 9d03de1f25
commit 3de0b8b7f0
4 changed files with 30 additions and 28 deletions
+20
View File
@@ -187,3 +187,23 @@ boost::filesystem::path dev::weaklyCanonicalFilesystemPath(boost::filesystem::pa
return head / tail;
}
}
string dev::absolutePath(string const& _path, string const& _reference)
{
boost::filesystem::path p(_path);
// Anything that does not start with `.` is an absolute path.
if (p.begin() == p.end() || (*p.begin() != "." && *p.begin() != ".."))
return _path;
boost::filesystem::path result(_reference);
result.remove_filename();
for (boost::filesystem::path::iterator it = p.begin(); it != p.end(); ++it)
if (*it == "..")
result = result.parent_path();
else if (*it != ".")
result /= *it;
return result.generic_string();
}
string dev::sanitizePath(string const& _path) {
return boost::filesystem::path(_path).generic_string();
}