summaryrefslogtreecommitdiffstats
path: root/Source/kwsys
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2005-05-04 15:37:01 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2005-05-04 15:37:01 (GMT)
commitfe110e2ae08a82bbf5ba096a9d39971d71ed2d72 (patch)
tree5b1b6763ce4c873e203daab1dba021992cced86c /Source/kwsys
parent37f2d32686d57b1c12822d6585b81134544a86c4 (diff)
downloadCMake-fe110e2ae08a82bbf5ba096a9d39971d71ed2d72.zip
CMake-fe110e2ae08a82bbf5ba096a9d39971d71ed2d72.tar.gz
CMake-fe110e2ae08a82bbf5ba096a9d39971d71ed2d72.tar.bz2
ENH: Add split that splits on arbitrary separator
Diffstat (limited to 'Source/kwsys')
-rw-r--r--Source/kwsys/SystemTools.cxx25
-rw-r--r--Source/kwsys/SystemTools.hxx.in1
2 files changed, 26 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx
index 5d4825b..ebb26dc 100644
--- a/Source/kwsys/SystemTools.cxx
+++ b/Source/kwsys/SystemTools.cxx
@@ -2466,6 +2466,31 @@ bool SystemTools::ComparePath(const char* c1, const char* c2)
#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)
{
kwsys_stl::string data(str);
diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in
index 59cd008..ca24616 100644
--- a/Source/kwsys/SystemTools.hxx.in
+++ b/Source/kwsys/SystemTools.hxx.in
@@ -189,6 +189,7 @@ public:
* 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, char separator);
/**
* Return string with space added between capitalized words