From eab3c7b2b9d250f15839b1f3b61197b0d77c5bd4 Mon Sep 17 00:00:00 2001 From: vsr Date: Wed, 25 Jan 2012 13:24:09 +0000 Subject: [PATCH] Fix bugs in GetDirFromPath() and GetNameFromPath() functions: they give wrong result if file is in the root directory. --- src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx index 89e955937..bf4461a84 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx @@ -171,11 +171,11 @@ void SALOMEDSImpl_Tool::RemoveTemporaryFiles(const std::string& theDirectory, std::string SALOMEDSImpl_Tool::GetNameFromPath(const std::string& thePath) { if (thePath.empty()) return ""; int pos = thePath.rfind('/'); - if(pos > 0) return thePath.substr(pos+1, thePath.size()); + if(pos >= 0) return thePath.substr(pos+1, thePath.size()); pos = thePath.rfind('\\'); - if(pos > 0) return thePath.substr(pos+1, thePath.size()); + if(pos >= 0) return thePath.substr(pos+1, thePath.size()); pos = thePath.rfind('|'); - if(pos > 0) return thePath.substr(pos+1, thePath.size()); + if(pos >= 0) return thePath.substr(pos+1, thePath.size()); return thePath; } @@ -196,7 +196,7 @@ std::string SALOMEDSImpl_Tool::GetDirFromPath(const std::string& thePath) { if (pos < 0) pos = thePath.rfind('\\'); if (pos < 0) pos = thePath.rfind('|'); - if (pos > 0) + if (pos >= 0) path = thePath.substr(0, pos+1); else path = std::string(".") + separator; -- 2.39.2