|
|
@@ -1123,19 +1123,27 @@ vector<string> VectorizeString(string const &haystack, char const &split)
|
|
|
/* This can be used to split a given string up into a vector of strings
|
|
|
* The seperator is a string
|
|
|
*/
|
|
|
-vector<string> StringSplit(string const &s, std::string const &sep)
|
|
|
+vector<string> StringSplit(string const &s, std::string const &sep,
|
|
|
+ unsigned int maxsplit)
|
|
|
{
|
|
|
vector<string> split;
|
|
|
size_t start, pos;
|
|
|
- start = pos = 0;
|
|
|
+
|
|
|
if(sep.size() == 0)
|
|
|
return split;
|
|
|
-
|
|
|
+
|
|
|
+ start = pos = 0;
|
|
|
do {
|
|
|
pos = s.find(sep, start);
|
|
|
split.push_back(s.substr(start, pos-start));
|
|
|
- if(pos != string::npos)
|
|
|
- start = pos+sep.size();
|
|
|
+
|
|
|
+ // deal with the max-split
|
|
|
+ if(maxsplit > 0 && split.size() >= maxsplit)
|
|
|
+ {
|
|
|
+ split[split.size()-1] = s.substr(start);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ start = pos+sep.size();
|
|
|
} while (pos != string::npos);
|
|
|
return split;
|
|
|
}
|