BUG: allow split string to know if it is separating a path

This commit is contained in:
Bill Hoffman 2004-10-14 11:46:30 -04:00
parent 78e8f12b86
commit ef8385744b
2 changed files with 13 additions and 7 deletions

View File

@ -1186,15 +1186,15 @@ bool cmSystemTools::CreateSymlink(const char* origName, const char* newName)
#endif #endif
std::vector<cmStdString> cmSystemTools::SplitString(const char* p, char sep) std::vector<cmStdString> cmSystemTools::SplitString(const char* p, char sep, bool isPath)
{ {
std::string path = p; std::string path = p;
std::vector<cmStdString> paths; std::vector<cmStdString> paths;
if(path[0] == '/') if(isPath && path[0] == '/')
{ {
path.erase(path.begin()); path.erase(path.begin());
paths.push_back("/");
} }
paths.push_back("/");
std::string::size_type pos1 = 0; std::string::size_type pos1 = 0;
std::string::size_type pos2 = path.find(sep, pos1+1); std::string::size_type pos2 = path.find(sep, pos1+1);
while(pos2 != std::string::npos) while(pos2 != std::string::npos)
@ -1232,8 +1232,9 @@ std::string cmSystemTools::RelativePath(const char* local, const char* remote)
} }
std::string relativePath; // result string std::string relativePath; // result string
// split up both paths into arrays of strings using / as a separator // split up both paths into arrays of strings using / as a separator
std::vector<cmStdString> fileSplit = cmSystemTools::SplitString(local); std::string localString = local;
std::vector<cmStdString> relativeSplit = cmSystemTools::SplitString(remote); std::vector<cmStdString> fileSplit = cmSystemTools::SplitString(local, '/', true);
std::vector<cmStdString> relativeSplit = cmSystemTools::SplitString(remote, '/', true);
std::vector<cmStdString> commonPath; std::vector<cmStdString> commonPath;
std::vector<cmStdString> finalPath; std::vector<cmStdString> finalPath;
// count up how many matching directory names there are from the start // count up how many matching directory names there are from the start

View File

@ -279,8 +279,13 @@ public:
*/ */
static std::string RelativePath(const char* local, const char* remote); static std::string RelativePath(const char* local, const char* remote);
///! split a path by separator into an array of strings, default is / /** split a path by separator into an array of strings, default is /.
static std::vector<cmStdString> SplitString(const char* s, char separator = '/'); If isPath is true then the string is treated like a path and if
s starts with a / then the first element of the returned array will
be /, so /foo/bar will be [/, foo, bar]
*/
static std::vector<cmStdString> SplitString(const char* s, char separator = '/',
bool isPath = false);
/** put a string into the environment /** put a string into the environment
of the form var=value */ of the form var=value */
static bool PutEnv(const char* value); static bool PutEnv(const char* value);