diff options
author | Michael Vogt <mvo@debian.org> | 2013-10-05 10:49:26 +0200 |
---|---|---|
committer | Michael Vogt <mvo@debian.org> | 2013-10-05 10:49:26 +0200 |
commit | b821e492d6dc4e1e8fd1f83590e12e3fbccad717 (patch) | |
tree | ac6d28f28fe13078aa578e1fb0fdd956a7e6ae84 /apt-pkg/contrib | |
parent | 318289bb17b827611fea6570f71df525b60a0e97 (diff) | |
parent | 75cd2506ce7ea411f7a0e888310d622ad330828c (diff) |
Merge remote-tracking branch 'mvo/bugfix/dpkg-progress-multiarch' into debian/sid
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 31 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 25 |
2 files changed, 55 insertions, 1 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 0955b69f7..77e48962c 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1118,6 +1118,37 @@ vector<string> VectorizeString(string const &haystack, char const &split) return exploded; } /*}}}*/ +// StringSplit - split a string into a string vector by token /*{{{*/ +// --------------------------------------------------------------------- +/* See header for details. + */ +vector<string> StringSplit(std::string const &s, std::string const &sep, + unsigned int maxsplit) +{ + vector<string> split; + size_t start, pos; + + // no seperator given, this is bogus + if(sep.size() == 0) + return split; + + start = pos = 0; + while (pos != string::npos) + { + pos = s.find(sep, start); + split.push_back(s.substr(start, pos-start)); + + // if maxsplit is reached, the remaining string is the last item + if(split.size() >= maxsplit) + { + split[split.size()-1] = s.substr(start); + break; + } + start = pos+sep.size(); + } + return split; +} + /*}}}*/ // RegexChoice - Simple regex list/list matcher /*{{{*/ // --------------------------------------------------------------------- /* */ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 530896141..b42e06491 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -17,7 +17,7 @@ #define STRUTL_H - +#include <limits> #include <stdlib.h> #include <string> #include <cstring> @@ -62,9 +62,32 @@ bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigned Base = 0) bool StrToNum(const char *Str,unsigned long long &Res,unsigned Len,unsigned Base = 0); bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len); bool Hex2Num(const std::string &Str,unsigned char *Num,unsigned int Length); + +// input changing string split bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); + +// split a given string by a char std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) __attrib_const; + +/* \brief Return a vector of strings from string "input" where "sep" + * is used as the delimiter string. + * + * \param input The input string. + * + * \param sep The seperator to use. + * + * \param maxsplit (optional) The maximum amount of splitting that + * should be done . + * + * The optional "maxsplit" argument can be used to limit the splitting, + * if used the string is only split on maxsplit places and the last + * item in the vector contains the remainder string. + */ +std::vector<std::string> StringSplit(std::string const &input, + std::string const &sep, + unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) __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); |