From 16dd98d9c74cd54a2956e1d982bb8877bcb731c4 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Thu, 22 Sep 2016 11:26:37 +0200 Subject: [PATCH] [BL] copyPathToFileName: Fix unexpected behaviour. --- BaseLib/FileTools.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp index 75525033b2c..caacb2ec574 100644 --- a/BaseLib/FileTools.cpp +++ b/BaseLib/FileTools.cpp @@ -123,6 +123,13 @@ bool hasFileExtension(std::string const& extension, std::string const& filename) return boost::iequals(extension, getFileExtension(filename)); } +static const char pathSeparator = +#ifdef _WIN32 + '\\'; +#else + '/'; +#endif + std::string copyPathToFileName(const std::string &file_name, const std::string &source) { @@ -131,6 +138,10 @@ std::string copyPathToFileName(const std::string &file_name, if (pos != std::string::npos) return file_name; + if (source.empty()) + return file_name; + if (source.back() != pathSeparator) + return BaseLib::extractPath(source + pathSeparator).append(file_name); return BaseLib::extractPath(source).append(file_name); } @@ -141,12 +152,6 @@ std::string extractPath(std::string const& pathname) return ""; return pathname.substr(0, pos + 1); } -static const char pathSeparator = -#ifdef _WIN32 - '\\'; -#else - '/'; -#endif std::string appendPathSeparator(std::string const& path) { -- GitLab