From: vsr Date: Thu, 20 Aug 2009 11:55:37 +0000 (+0000) Subject: Fix bug in GetDirFromPath() function - wrong directory is returned if the file in... X-Git-Tag: V5_1_3rc1~83 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=70672f698460ec7be7393ab83f2db564b79a0188;p=modules%2Fkernel.git Fix bug in GetDirFromPath() function - wrong directory is returned if the file in the current directory is specified --- 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; }