From d8354e65c90159e388b794d0b7bcd5ac539d3524 Mon Sep 17 00:00:00 2001 From: Sebastien Barre Date: Thu, 24 May 2001 19:17:47 -0400 Subject: [PATCH] optimize ConvertToUnixSlashes a little bit, and use it in MakeDirectory (code was duplicated) --- Source/cmSystemTools.cxx | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 3e9642f9a..f5247508d 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -126,14 +126,10 @@ const char* cmSystemTools::GetExecutableExtension() bool cmSystemTools::MakeDirectory(const char* path) { std::string dir = path; - // replace all of the \ with / - size_t pos = 0; - while((pos = dir.find('\\', pos)) != std::string::npos) - { - dir[pos] = '/'; - pos++; - } - pos = dir.find(':'); + + cmSystemTools::ConvertToUnixSlashes(dir); + + std::string::size_type pos = dir.find(':'); if(pos == std::string::npos) { pos = 0; @@ -334,11 +330,11 @@ std::string cmSystemTools::Capitalized(std::string& s) // convert windows slashes to unix slashes \ with / void cmSystemTools::ConvertToUnixSlashes(std::string& path) { - std::string::size_type pos = path.find('\\'); - while(pos != std::string::npos) + std::string::size_type pos = 0; + while((pos = path.find('\\', pos)) != std::string::npos) { path[pos] = '/'; - pos = path.find('\\'); + pos++; } // remove any trailing slash if(path[path.size()-1] == '/') @@ -892,9 +888,9 @@ void cmSystemTools::SplitProgramPath(const char* in_name, if(!cmSystemTools::FileIsDirectory(dir.c_str())) { std::string::size_type slashPos = dir.rfind("/"); - if(slashPos != std::string::npos) + if(slashPos != std::string::npos) { - file = dir.substr(slashPos+1) + file; + file = dir.substr(slashPos+1); dir = dir.substr(0, slashPos); } else