ENH: Add split that splits on arbitrary separator
This commit is contained in:
parent
37f2d32686
commit
fe110e2ae0
@ -2466,6 +2466,31 @@ bool SystemTools::ComparePath(const char* c1, const char* c2)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines, char separator)
|
||||||
|
{
|
||||||
|
kwsys_stl::string data(str);
|
||||||
|
kwsys_stl::string::size_type lpos = 0;
|
||||||
|
while(lpos < data.length())
|
||||||
|
{
|
||||||
|
kwsys_stl::string::size_type rpos = data.find_first_of(separator, lpos);
|
||||||
|
if(rpos == kwsys_stl::string::npos)
|
||||||
|
{
|
||||||
|
// Line ends at end of string without a newline.
|
||||||
|
lines.push_back(data.substr(lpos));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Line ends in a "\n", remove the character.
|
||||||
|
lines.push_back(data.substr(lpos, rpos-lpos));
|
||||||
|
}
|
||||||
|
lpos = rpos+1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines)
|
bool SystemTools::Split(const char* str, kwsys_stl::vector<kwsys_stl::string>& lines)
|
||||||
{
|
{
|
||||||
kwsys_stl::string data(str);
|
kwsys_stl::string data(str);
|
||||||
|
@ -189,6 +189,7 @@ public:
|
|||||||
* Return false only if the last line stored had no newline
|
* Return false only if the last line stored had no newline
|
||||||
*/
|
*/
|
||||||
static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l);
|
static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l);
|
||||||
|
static bool Split(const char* s, kwsys_stl::vector<kwsys_stl::string>& l, char separator);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return string with space added between capitalized words
|
* Return string with space added between capitalized words
|
||||||
|
Loading…
x
Reference in New Issue
Block a user