aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2008-02-20 19:41:22 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2008-02-20 19:41:22 +0000
commite18bc08fbc674584fe3a3a0c6b866a5aea201a91 (patch)
tree12c9ee8ce537a0c59afd0a422ff47d7f4c831d9b
parentdd4d45337b80ce73926e7a9ffc3b668da6d008f0 (diff)
downloadexternal_llvm-e18bc08fbc674584fe3a3a0c6b866a5aea201a91.zip
external_llvm-e18bc08fbc674584fe3a3a0c6b866a5aea201a91.tar.gz
external_llvm-e18bc08fbc674584fe3a3a0c6b866a5aea201a91.tar.bz2
Add convenient helper to get suffix of the file
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47397 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/System/Path.h8
-rw-r--r--lib/System/Path.cpp5
2 files changed, 12 insertions, 1 deletions
diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h
index 3ab9e08..db1de77 100644
--- a/include/llvm/System/Path.h
+++ b/include/llvm/System/Path.h
@@ -266,6 +266,14 @@ namespace sys {
/// @brief Get the base name of the path
std::string getBasename() const;
+ /// This function strips off the path and basename(up to and
+ /// including the last dot) of the file or directory name and
+ /// returns just the suffix. For example /a/foo.bar would cause
+ /// this function to return "bar".
+ /// @returns std::string containing the suffix of the path
+ /// @brief Get the suffix of the path
+ std::string getSuffix() const;
+
/// Obtain a 'C' string for the path name.
/// @returns a 'C' string containing the path name.
/// @brief Returns the path as a C string.
diff --git a/lib/System/Path.cpp b/lib/System/Path.cpp
index 6f0667f..11035cf 100644
--- a/lib/System/Path.cpp
+++ b/lib/System/Path.cpp
@@ -172,7 +172,10 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
return false;
}
-
+std::string
+Path::getSuffix() const {
+ return path.substr(path.rfind('.') + 1);
+}
// Include the truly platform-specific parts of this class.
#if defined(LLVM_ON_UNIX)