summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2002-10-11 14:16:01 (GMT)
committerBrad King <brad.king@kitware.com>2002-10-11 14:16:01 (GMT)
commita8d038dbd0c64a22d35c10c71f4b59da1cadc3f4 (patch)
treec05672469848d0abde960c8af461216a60341142 /Source/cmSystemTools.cxx
parent3d3d7a91469eb0f9bdababe3497849614ac99bb0 (diff)
downloadCMake-a8d038dbd0c64a22d35c10c71f4b59da1cadc3f4.zip
CMake-a8d038dbd0c64a22d35c10c71f4b59da1cadc3f4.tar.gz
CMake-a8d038dbd0c64a22d35c10c71f4b59da1cadc3f4.tar.bz2
ENH: Added Split method to cmSystemTools to split a string into lines on its newlines.
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r--Source/cmSystemTools.cxx28
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index 1941165..8bcaa84 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -1894,6 +1894,34 @@ std::string cmSystemTools::CollapseFullPath(const char* in_name)
#endif
}
+bool cmSystemTools::Split(const char* str, std::vector<cmStdString>& lines)
+{
+ std::string data(str);
+ std::string::size_type lpos = 0;
+ while(lpos < data.length())
+ {
+ std::string::size_type rpos = data.find_first_of("\n", lpos);
+ if(rpos == std::string::npos)
+ {
+ // Line ends at end of string without a newline.
+ lines.push_back(data.substr(lpos));
+ return false;
+ }
+ if((rpos > lpos) && (data[rpos-1] == '\r'))
+ {
+ // Line ends in a "\r\n" pair, remove both characters.
+ lines.push_back(data.substr(lpos, (rpos-1)-lpos));
+ }
+ else
+ {
+ // Line ends in a "\n", remove the character.
+ lines.push_back(data.substr(lpos, rpos-lpos));
+ }
+ lpos = rpos+1;
+ }
+ return true;
+}
+
/**
* Return path of a full filename (no trailing slashes).
* Warning: returned path is converted to Unix slashes format.