From 9572a54bbc96eb653b3e13260abb183ba7a316f3 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 7 Sep 2013 16:16:49 +0200 Subject: doc update --- apt-pkg/contrib/strutl.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'apt-pkg/contrib/strutl.cc') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 508af8922..fd768f183 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1118,10 +1118,11 @@ vector VectorizeString(string const &haystack, char const &split) return exploded; } /*}}}*/ -// StringSplit - like python string.split /*{{{*/ +// StringSplit - split a string into a string vector by token /*{{{*/ // --------------------------------------------------------------------- -/* This can be used to split a given string up into a vector of strings - * The seperator is a string +/* This can be used to split a given string up from a given string token + * into a vector of strings. A optional "maxsplit" argument can be used + * to limit the splitting, in this case the */ vector StringSplit(string const &s, std::string const &sep, unsigned int maxsplit) @@ -1129,22 +1130,24 @@ vector StringSplit(string const &s, std::string const &sep, vector split; size_t start, pos; + // no seperator given, this is bogus if(sep.size() == 0) return split; start = pos = 0; - do { + while (pos != string::npos) + { pos = s.find(sep, start); split.push_back(s.substr(start, pos-start)); - // deal with the max-split + // if maxsplit is reached, the remaining string is the last item if(maxsplit > 0 && split.size() >= maxsplit) { split[split.size()-1] = s.substr(start); break; } start = pos+sep.size(); - } while (pos != string::npos); + } return split; } /*}}}*/ -- cgit v1.2.3