summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/strutl.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-09-07 12:19:51 +0200
committerMichael Vogt <mvo@debian.org>2013-09-07 12:19:51 +0200
commit00f4d9ffa3468e899abf8fbda8db71fc3143b8e5 (patch)
tree7a32bb35ba43285f5d24f7c07ad8347b5ca499e5 /apt-pkg/contrib/strutl.cc
parent968179cf7b9e1a633c283745da15755d8de4acbd (diff)
implement StringSplit() as we need this to fix the dpkg status-fd output parsing
Diffstat (limited to 'apt-pkg/contrib/strutl.cc')
-rw-r--r--apt-pkg/contrib/strutl.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 0955b69f7..819d50de0 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1118,6 +1118,28 @@ vector<string> VectorizeString(string const &haystack, char const &split)
return exploded;
}
/*}}}*/
+// StringSplit - like python string.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> split;
+ size_t start, pos;
+ start = pos = 0;
+ if(sep.size() == 0)
+ return split;
+
+ do {
+ pos = s.find(sep, start);
+ split.push_back(s.substr(start, pos-start));
+ if(pos != string::npos)
+ start = pos+sep.size();
+ } while (pos != string::npos);
+ return split;
+}
+ /*}}}*/
// RegexChoice - Simple regex list/list matcher /*{{{*/
// ---------------------------------------------------------------------
/* */