diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-07-08 12:24:56 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-07-08 12:24:56 -0400 |
commit | 66684c6690d43c8f3277e1b07e1d86b372cd5f3a (patch) | |
tree | 51cce43abe3ef49771d525852fe2451d758fdddc | |
parent | fcabd5d8ee172e9d27423864448902ad99634ac5 (diff) |
Add PBD::get_suffix() for ripping file suffixes from paths
-rw-r--r-- | libs/pbd/file_utils.cc | 10 | ||||
-rw-r--r-- | libs/pbd/pbd/file_utils.h | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc index 311d22f9e0..0877ceacbc 100644 --- a/libs/pbd/file_utils.cc +++ b/libs/pbd/file_utils.cc @@ -336,6 +336,16 @@ get_absolute_path (const std::string & p) return Glib::build_filename (Glib::get_current_dir(), p); } +std::string +get_suffix (const std::string & p) +{ + string::size_type period = p.find_last_of ('.'); + if (period == string::npos || period == p.length() - 1) { + return string(); + } + return p.substr (period+1); +} + bool equivalent_paths (const std::string& a, const std::string& b) { diff --git a/libs/pbd/pbd/file_utils.h b/libs/pbd/pbd/file_utils.h index 9ef5374a0a..cb0aa38065 100644 --- a/libs/pbd/pbd/file_utils.h +++ b/libs/pbd/pbd/file_utils.h @@ -182,6 +182,13 @@ LIBPBD_API void copy_files(const std::string & from_path, const std::string & to LIBPBD_API std::string get_absolute_path (const std::string &); /** + * Take a path/filename and return the suffix (characters beyond the last '.' + * @return A string containing the suffix, which will be empty + * if there are no '.' characters in the path/filename. + */ +LIBPBD_API std::string get_suffix (const std::string &); + +/** * Find out if `needle' is a file or directory within the * directory `haystack'. * @return true if it is. |