From 9d83b34d02384b93e5487751a091ea90a6dc4a3a Mon Sep 17 00:00:00 2001 From: Dmitrij Naumov <dmitrij@naumov.de> Date: Wed, 31 Oct 2012 14:19:03 +0100 Subject: [PATCH] Add dropFileExtension() and findLastDot(). --- BaseLib/FileTools.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 99454bea783..e94d8cb0013 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -64,6 +64,20 @@ size_t findLastPathSeparator(std::string const& path) return path.find_last_of("/\\"); } +size_t findLastDot(std::string const& path) +{ + return path.find_last_of("."); +} + +std::string dropFileExtension(std::string const& filename) +{ + const size_t p = findLastDot(filename); + if (p == std::string::npos) + return filename; + + return filename.substr(0, filename.length() - p); +} + std::string getFileNameFromPath(const std::string &str, bool with_extension) { std::string::size_type beg1 = str.find_last_of('/'); -- GitLab