diff options
author | chriseth <chris@ethereum.org> | 2018-08-07 22:15:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-07 22:15:49 +0800 |
commit | 901550e473f001d2c6666870d71dbf0b9ff8c1ff (patch) | |
tree | 8386cd8229ab7faf39787bc4b3ab92bd5e573a52 /libdevcore/CommonIO.cpp | |
parent | a949cffd248cf83a6afa4d5a45376d65b720ba52 (diff) | |
parent | 3de0b8b7f002bdc76e629f89df73523b36a169f5 (diff) | |
download | dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.tar dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.tar.gz dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.tar.bz2 dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.tar.lz dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.tar.xz dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.tar.zst dexon-solidity-901550e473f001d2c6666870d71dbf0b9ff8c1ff.zip |
Merge pull request #4692 from ethereum/devcore-path
Move absolutePath/sanitizePath helpers from CompilerStack to libdevcore
Diffstat (limited to 'libdevcore/CommonIO.cpp')
-rw-r--r-- | libdevcore/CommonIO.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index 0063a8d4..9693d02a 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -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(); +} |