CMake: Move tokenize to cmSystemTools

This commit is contained in:
Johan Björk 2011-02-15 14:34:14 +01:00 committed by Brad King
parent d4884710a4
commit d0a403fd99
3 changed files with 36 additions and 32 deletions

View File

@ -11,37 +11,6 @@
============================================================================*/ ============================================================================*/
#include "cmSourceGroupCommand.h" #include "cmSourceGroupCommand.h"
inline std::vector<std::string> tokenize(const std::string& str,
const std::string& sep)
{
std::vector<std::string> tokens;
std::string::size_type tokend = 0;
do
{
std::string::size_type tokstart=str.find_first_not_of(sep, tokend);
if (tokstart==std::string::npos)
{
break; // no more tokens
}
tokend=str.find_first_of(sep,tokstart);
if (tokend==std::string::npos)
{
tokens.push_back(str.substr(tokstart));
}
else
{
tokens.push_back(str.substr(tokstart,tokend-tokstart));
}
} while (tokend!=std::string::npos);
if (tokens.empty())
{
tokens.push_back("");
}
return tokens;
}
// cmSourceGroupCommand // cmSourceGroupCommand
bool cmSourceGroupCommand bool cmSourceGroupCommand
::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
@ -58,7 +27,7 @@ bool cmSourceGroupCommand
delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"); delimiter = this->Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
} }
std::vector<std::string> folders = tokenize(args[0], delimiter); std::vector<std::string> folders = cmSystemTools::tokenize(args[0], delimiter);
cmSourceGroup* sg = 0; cmSourceGroup* sg = 0;
sg = this->Makefile->GetSourceGroup(folders); sg = this->Makefile->GetSourceGroup(folders);

View File

@ -2833,3 +2833,35 @@ bool cmSystemTools::RepeatedRemoveDirectory(const char* dir)
} }
return false; return false;
} }
//----------------------------------------------------------------------------
std::vector<std::string> cmSystemTools::tokenize(const std::string& str,
const std::string& sep)
{
std::vector<std::string> tokens;
std::string::size_type tokend = 0;
do
{
std::string::size_type tokstart=str.find_first_not_of(sep, tokend);
if (tokstart==std::string::npos)
{
break; // no more tokens
}
tokend=str.find_first_of(sep,tokstart);
if (tokend==std::string::npos)
{
tokens.push_back(str.substr(tokstart));
}
else
{
tokens.push_back(str.substr(tokstart,tokend-tokstart));
}
} while (tokend!=std::string::npos);
if (tokens.empty())
{
tokens.push_back("");
}
return tokens;
}

View File

@ -439,6 +439,9 @@ public:
/** Remove a directory; repeat a few times in case of locked files. */ /** Remove a directory; repeat a few times in case of locked files. */
static bool RepeatedRemoveDirectory(const char* dir); static bool RepeatedRemoveDirectory(const char* dir);
/** Tokenize a string */
static std::vector<std::string> tokenize(const std::string& str,
const std::string& sep);
private: private:
static bool s_ForceUnixPaths; static bool s_ForceUnixPaths;
static bool s_RunCommandHideConsole; static bool s_RunCommandHideConsole;