Add PBD::get_suffix() for ripping file suffixes from paths

This commit is contained in:
Paul Davis 2014-07-08 12:24:56 -04:00
parent fcabd5d8ee
commit 66684c6690
2 changed files with 17 additions and 0 deletions

View File

@ -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)
{

View File

@ -181,6 +181,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'.