aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System/Path.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-07 21:53:57 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-07 21:53:57 +0000
commitcf55c8e221c1d31a361f99ee49078d261cdf431c (patch)
treeffd732ba6a0d8ee6a30846cab129eb6143a244d8 /lib/System/Path.cpp
parenta0562001d05101975ec88248a0bb5518074543dc (diff)
downloadexternal_llvm-cf55c8e221c1d31a361f99ee49078d261cdf431c.zip
external_llvm-cf55c8e221c1d31a361f99ee49078d261cdf431c.tar.gz
external_llvm-cf55c8e221c1d31a361f99ee49078d261cdf431c.tar.bz2
Added method Path::getDirname().
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Path.cpp')
-rw-r--r--lib/System/Path.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp
index 8a1de75..43c36d5 100644
--- a/lib/System/Path.cpp
+++ b/lib/System/Path.cpp
@@ -196,6 +196,45 @@ static void getPathList(const char*path, std::vector<Path>& Paths) {
Paths.push_back(tmpPath);
}
+std::string Path::getDirnameCharSep(char Sep) const {
+
+ if (path.empty())
+ return ".";
+
+ // If the path is all slashes, return a single slash.
+ // Otherwise, remove all trailing slashes.
+
+ signed pos = path.size() - 1;
+
+ while (pos >= 0 && path[pos] == Sep)
+ --pos;
+
+ if (pos < 0)
+ return path[0] == Sep ? std::string(1, Sep) : std::string(".");
+
+ // Any slashes left?
+ signed i = 0;
+
+ while (i < pos && path[i] != Sep)
+ ++i;
+
+ if (i == pos) // No slashes? Return "."
+ return ".";
+
+ // There is at least one slash left. Remove all trailing non-slashes.
+ while (pos >= 0 && path[pos] != Sep)
+ --pos;
+
+ // Remove any trailing slashes.
+ while (pos >= 0 && path[pos] == Sep)
+ --pos;
+
+ if (pos < 0)
+ return path[0] == Sep ? std::string(1, Sep) : std::string(".");
+
+ return path.substr(0, pos+1);
+}
+
// Include the truly platform-specific parts of this class.
#if defined(LLVM_ON_UNIX)
#include "Unix/Path.inc"