From: dooglus Date: Sun, 14 Oct 2007 21:20:47 +0000 (+0000) Subject: Wrote filename_extension() and filename_sans_extension(), since they are reimplemente... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=8ecddf5b31db7541fd7639a437007f0d3597a5b2;p=synfig.git Wrote filename_extension() and filename_sans_extension(), since they are reimplemented (often incorrectly) in lots of places. git-svn-id: http://svn.voria.com/code@928 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/ETL/trunk/ETL/_stringf.h b/ETL/trunk/ETL/_stringf.h index b702689..8173214 100644 --- a/ETL/trunk/ETL/_stringf.h +++ b/ETL/trunk/ETL/_stringf.h @@ -198,6 +198,28 @@ dirname(const std::string &str) return std::string(str.begin(),iter); } +// filename_extension("/f.e/d.c") => ".c" +inline std::string +filename_extension(const std::string &str) +{ + std::string base = basename(str); + std::string::size_type pos = base.find_last_of('.'); + if (pos == std::string::npos) return std::string(); + return base.substr(pos); +} + +// filename_sans_extension("/f.e/d.c") => "/f.e/d" +inline std::string +filename_sans_extension(const std::string &str) +{ + std::string base = basename(str); + std::string::size_type pos = base.find_last_of('.'); + if (pos == std::string::npos) return str; + std::string dir = dirname(str); + if (dir == ".") return base.substr(0,pos); + return dir + ETL_DIRECTORY_SEPARATOR + base.substr(0,pos); +} + inline bool is_absolute_path(const std::string &path) {