From 70672f698460ec7be7393ab83f2db564b79a0188 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 20 Aug 2009 11:55:37 +0000 Subject: [PATCH] Fix bug in GetDirFromPath() function - wrong directory is returned if the file in the current directory is specified --- src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx index e19d888f6..898d8d67e 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Tool.cxx @@ -184,31 +184,31 @@ string SALOMEDSImpl_Tool::GetNameFromPath(const string& thePath) { // purpose : Returns the dir by the path //============================================================================ string SALOMEDSImpl_Tool::GetDirFromPath(const string& thePath) { - if (thePath.empty()) return ""; +#ifdef WIN32 + string separator = "\\"; +#else + string separator = "/"; +#endif - int pos = thePath.rfind('/'); string path; - if(pos > 0) { - path = thePath.substr(0, pos+1); - } - if(path.empty()) { - pos = thePath.rfind('\\'); - if(pos > 0) path = thePath.substr(0, pos+1); - } - if(path.empty()) { - pos = thePath.rfind('|'); - if(pos > 0) path = thePath.substr(0, pos+1); - } - if(path.empty()) { - path = thePath+"/"; - } - + if (!thePath.empty()) { + int pos = thePath.rfind('/'); + if (pos < 0) pos = thePath.rfind('\\'); + if (pos < 0) pos = thePath.rfind('|'); + + if (pos > 0) + path = thePath.substr(0, pos+1); + else + path = string(".") + separator; + #ifdef WIN32 //Check if the only disk letter is given as path - if(path.size() == 2 && path[1] == ':') path +='\\'; + if (path.size() == 2 && path[1] == ':') path += separator; #endif - - for(int i = 0, len = path.size(); i= 0 ) + path.replace(pos, 1, separator); + } + return path; } -- 2.39.2