summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/strutl.cc22
-rw-r--r--apt-pkg/contrib/strutl.h2
2 files changed, 24 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 /*{{{*/
// ---------------------------------------------------------------------
/* */
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 530896141..c97246c90 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -65,6 +65,8 @@ bool Hex2Num(const std::string &Str,unsigned char *Num,unsigned int Length);
bool TokSplitString(char Tok,char *Input,char **List,
unsigned long ListMax);
std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) __attrib_const;
+// like python string.split
+std::vector<std::string> StringSplit(std::string const &haystack, std::string const &sep) __attrib_const;
void ioprintf(std::ostream &out,const char *format,...) __like_printf(2);
void strprintf(std::string &out,const char *format,...) __like_printf(2);
char *safe_snprintf(char *Buffer,char *End,const char *Format,...) __like_printf(3);