Add PBD::sys::extension for getting the filename extension of a file
authorTim Mayberry <mojofunk@gmail.com>
Tue, 4 Sep 2007 09:01:17 +0000 (09:01 +0000)
committerTim Mayberry <mojofunk@gmail.com>
Tue, 4 Sep 2007 09:01:17 +0000 (09:01 +0000)
git-svn-id: svn://localhost/ardour2/trunk@2405 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/pbd/filesystem.cc
libs/pbd/pbd/filesystem.h

index ea45b1da44f34b38ecbd03604f95f50c0b01f06d..3c96f5b0019e48378b5cf43857b27639a8584b3f 100644 (file)
@@ -162,6 +162,22 @@ basename (const path & p)
        return base.substr (0, n);
 }
 
+string
+extension (const path & p)
+{
+       string base = Glib::path_get_basename (p.to_string());
+
+       string::size_type n = base.rfind ('.');
+
+       if (n != string::npos)
+       {
+               return base.substr(n);
+       }
+
+       return string();
+
+}
+
 } // namespace sys
 
 } // namespace PBD
index b5f328acf4bb4c228856d2c83b60bf6725d99519..5e94138bd869e39029eb26006d68da6e54c3a6a8 100644 (file)
@@ -172,6 +172,15 @@ void copy_file(const path & from_path, const path & to_path);
  */ 
 string basename (const path& p);
 
+/**
+ * @return If the filename contains a dot, return a substring of the
+ * filename starting the rightmost dot to the end of the string, otherwise
+ * an empty string.
+ *
+ * @param p a file path.
+ */
+string extension (const path& p);
+
 } // namespace sys
 
 } // namespace PBD