Add convenient helper to get suffix of the file
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 20 Feb 2008 19:41:22 +0000 (19:41 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 20 Feb 2008 19:41:22 +0000 (19:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47397 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/System/Path.h
lib/System/Path.cpp

index 3ab9e087b0ce53b1737b9adf39f290ff2e0dff53..db1de770fc2876e33af29cd18ebd0bef90a82b61 100644 (file)
@@ -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.
index 6f0667fba509d1ab7314cde74a96cdfbc547476b..11035cfee7aa55d6ba55973905eeebd730a44934 100644 (file)
@@ -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)