summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorTim Mayberry <mojofunk@gmail.com>2007-09-04 09:01:17 +0000
committerTim Mayberry <mojofunk@gmail.com>2007-09-04 09:01:17 +0000
commit8b160ef5000f7160bfcb993e2c478c64d784c085 (patch)
tree4b5f0d1fa4887013f9462298004382fc7ceaa582 /libs/pbd
parent4cf84efe8896d7be295993418bbde9e5d3c0cfee (diff)
Add PBD::sys::extension for getting the filename extension of a file
git-svn-id: svn://localhost/ardour2/trunk@2405 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/filesystem.cc16
-rw-r--r--libs/pbd/pbd/filesystem.h9
2 files changed, 25 insertions, 0 deletions
diff --git a/libs/pbd/filesystem.cc b/libs/pbd/filesystem.cc
index ea45b1da44..3c96f5b001 100644
--- a/libs/pbd/filesystem.cc
+++ b/libs/pbd/filesystem.cc
@@ -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
diff --git a/libs/pbd/pbd/filesystem.h b/libs/pbd/pbd/filesystem.h
index b5f328acf4..5e94138bd8 100644
--- a/libs/pbd/pbd/filesystem.h
+++ b/libs/pbd/pbd/filesystem.h
@@ -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