From a701cefd9c28c7ff53f6a4e0ed55b37c905a33f1 Mon Sep 17 00:00:00 2001 From: Dmitrij Naumov <dmitrij@naumov.de> Date: Wed, 31 Oct 2012 23:13:45 +0100 Subject: [PATCH] Rewrite copyPathToFileName(). --- BaseLib/FileTools.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 9a0d28b3bc1..3fef890ea66 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -114,21 +114,15 @@ bool hasFileExtension(std::string const& extension, std::string const& filename) return ext == file_ext; } -std::string copyPathToFileName(const std::string &file_name, const std::string &source) +std::string copyPathToFileName(const std::string &file_name, + const std::string &source) { // check if file_name already contains a full path - size_t pos(file_name.rfind("/")); // linux, mac delimiter - if (pos == std::string::npos) - { - pos = file_name.rfind("\\"); // windows delimiter - if (pos == std::string::npos) - { - std::string path = BaseLib::extractPath(source); - return path.append(file_name); - } - else return std::string(file_name); - } - else return std::string(file_name); + const size_t pos = findLastPathSeparator(file_name); + if (pos != std::string::npos) + return file_name; + + return BaseLib::extractPath(source).append(file_name); } std::string extractPath(std::string const& pathname) -- GitLab