diff options
author | Mike Aizatsky <aizatsky@chromium.org> | 2015-11-09 18:56:31 +0000 |
---|---|---|
committer | Mike Aizatsky <aizatsky@chromium.org> | 2015-11-09 18:56:31 +0000 |
commit | 662b4fd325d410181d91031f0155e60c520eebe6 (patch) | |
tree | 283c6efc13f982c838ebef8a9941ed79ec6f7c73 /llvm/lib/Support/Path.cpp | |
parent | cee6a6a63b56c9317dd73edefa93ea35037fa2f6 (diff) | |
download | bcm5719-llvm-662b4fd325d410181d91031f0155e60c520eebe6.tar.gz bcm5719-llvm-662b4fd325d410181d91031f0155e60c520eebe6.zip |
Moving FileManager::removeDotPaths to llvm::sys::path::remove_dots
Differential Revision: http://reviews.llvm.org/D14393
llvm-svn: 252499
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index f45774bca7b..4952f59fc24 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -671,6 +671,41 @@ StringRef remove_leading_dotslash(StringRef Path) { return Path; } +static SmallString<256> remove_dots(StringRef path, bool remove_dot_dot) { + SmallVector<StringRef, 16> components; + + // Skip the root path, then look for traversal in the components. + StringRef rel = path::relative_path(path); + for (StringRef C : llvm::make_range(path::begin(rel), path::end(rel))) { + if (C == ".") + continue; + if (remove_dot_dot) { + if (C == "..") { + if (!components.empty()) + components.pop_back(); + continue; + } + } + components.push_back(C); + } + + SmallString<256> buffer = path::root_path(path); + for (StringRef C : components) + path::append(buffer, C); + return buffer; +} + +bool remove_dots(SmallVectorImpl<char> &path, bool remove_dot_dot) { + StringRef p(path.data(), path.size()); + + SmallString<256> result = remove_dots(p, remove_dot_dot); + if (result == path) + return false; + + path.swap(result); + return true; +} + } // end namespace path namespace fs { |