optimize ConvertToUnixSlashes a little bit, and use it in MakeDirectory (code was duplicated)

This commit is contained in:
Sebastien Barre 2001-05-24 19:17:47 -04:00
parent 296649209c
commit d8354e65c9
1 changed files with 9 additions and 13 deletions

View File

@ -126,14 +126,10 @@ const char* cmSystemTools::GetExecutableExtension()
bool cmSystemTools::MakeDirectory(const char* path) bool cmSystemTools::MakeDirectory(const char* path)
{ {
std::string dir = path; std::string dir = path;
// replace all of the \ with /
size_t pos = 0; cmSystemTools::ConvertToUnixSlashes(dir);
while((pos = dir.find('\\', pos)) != std::string::npos)
{ std::string::size_type pos = dir.find(':');
dir[pos] = '/';
pos++;
}
pos = dir.find(':');
if(pos == std::string::npos) if(pos == std::string::npos)
{ {
pos = 0; pos = 0;
@ -334,11 +330,11 @@ std::string cmSystemTools::Capitalized(std::string& s)
// convert windows slashes to unix slashes \ with / // convert windows slashes to unix slashes \ with /
void cmSystemTools::ConvertToUnixSlashes(std::string& path) void cmSystemTools::ConvertToUnixSlashes(std::string& path)
{ {
std::string::size_type pos = path.find('\\'); std::string::size_type pos = 0;
while(pos != std::string::npos) while((pos = path.find('\\', pos)) != std::string::npos)
{ {
path[pos] = '/'; path[pos] = '/';
pos = path.find('\\'); pos++;
} }
// remove any trailing slash // remove any trailing slash
if(path[path.size()-1] == '/') if(path[path.size()-1] == '/')
@ -894,7 +890,7 @@ void cmSystemTools::SplitProgramPath(const char* in_name,
std::string::size_type slashPos = dir.rfind("/"); 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); dir = dir.substr(0, slashPos);
} }
else else