ENH: Windows and Unix slash conversions return a char*, clean function

seperated from Convert function
This commit is contained in:
John Biddiscombe 2001-09-01 16:13:56 -04:00
parent 0645a50061
commit 5ac8ecd9d2
2 changed files with 21 additions and 8 deletions

View File

@ -403,7 +403,7 @@ std::string cmSystemTools::Capitalized(const std::string& s)
// convert windows slashes to unix slashes \ with / // convert windows slashes to unix slashes \ with /
void cmSystemTools::ConvertToUnixSlashes(std::string& path) const char *cmSystemTools::ConvertToUnixSlashes(std::string& path)
{ {
std::string::size_type pos = 0; std::string::size_type pos = 0;
while((pos = path.find('\\', pos)) != std::string::npos) while((pos = path.find('\\', pos)) != std::string::npos)
@ -416,10 +416,11 @@ void cmSystemTools::ConvertToUnixSlashes(std::string& path)
{ {
path = path.substr(0, path.size()-1); path = path.substr(0, path.size()-1);
} }
return path.c_str();
} }
// convert windows slashes to unix slashes \ with / // convert windows slashes to unix slashes
void cmSystemTools::CleanUpWindowsSlashes(std::string& path) const char *cmSystemTools::ConvertToWindowsSlashes(std::string& path)
{ {
std::string::size_type pos = 0; std::string::size_type pos = 0;
while((pos = path.find('/', pos)) != std::string::npos) while((pos = path.find('/', pos)) != std::string::npos)
@ -432,15 +433,22 @@ void cmSystemTools::CleanUpWindowsSlashes(std::string& path)
{ {
path = path.substr(0, path.size()-1); path = path.substr(0, path.size()-1);
} }
// remove any duplicate // slashes return path.c_str();
}
// convert Unix slashes / to Windows slashes \ and cleanup double \\
const char *cmSystemTools::ConvertToWindowsSlashesAndCleanUp(std::string& path)
{
cmSystemTools::ConvertToWindowsSlashes(path);
std::string::size_type pos = 0;
pos = 0; pos = 0;
while((pos = path.find("\\\\", pos)) != std::string::npos) while((pos = path.find("\\\\", pos)) != std::string::npos)
{ {
path.erase(pos, 1); path.erase(pos, 1);
} }
return path.c_str();
} }
bool cmSystemTools::ParseFunction(std::ifstream& fin, bool cmSystemTools::ParseFunction(std::ifstream& fin,
std::string& name, std::string& name,
std::vector<std::string>& arguments) std::vector<std::string>& arguments)

View File

@ -98,13 +98,18 @@ public:
/** /**
* Replace Windows file system slashes with Unix-style slashes. * Replace Windows file system slashes with Unix-style slashes.
*/ */
static void ConvertToUnixSlashes(std::string& path); static const char *ConvertToUnixSlashes(std::string& path);
/**
* Replace Unix file system slashes with Windows-style slashes
*/
static const char *ConvertToWindowsSlashes(std::string& path);
/** /**
* Replace Unix file system slashes with Windows-style slashes and * Replace Unix file system slashes with Windows-style slashes and
* remove any duplicate slashes to clean the path. * remove any duplicate \\ slashes to clean the path.
*/ */
static void CleanUpWindowsSlashes(std::string& path); static const char *ConvertToWindowsSlashesAndCleanUp(std::string& path);
///! Return true if a file exists in the current directory. ///! Return true if a file exists in the current directory.
static bool FileExists(const char* filename); static bool FileExists(const char* filename);