]> git.saurik.com Git - apt.git/commitdiff
Merge remote-tracking branch 'origin/bugfix/dpkg-progress-multiarch' into bugfix...
authorMichael Vogt <mvo@debian.org>
Wed, 2 Oct 2013 08:15:52 +0000 (10:15 +0200)
committerMichael Vogt <mvo@debian.org>
Wed, 2 Oct 2013 08:15:52 +0000 (10:15 +0200)
apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h
test/libapt/strutil_test.cc

index fd768f18328371b98138bbcb44ff777fdc195478..77e48962c086ec7be659736b1fd6e9d62e303994 100644 (file)
@@ -1120,11 +1120,9 @@ vector<string> VectorizeString(string const &haystack, char const &split)
                                                                        /*}}}*/
 // StringSplit - split a string into a string vector by token          /*{{{*/
 // ---------------------------------------------------------------------
-/* 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 
+/* See header for details.
  */
-vector<string> StringSplit(string const &s, std::string const &sep,
+vector<string> StringSplit(std::string const &s, std::string const &sep,
                            unsigned int maxsplit)
 {
    vector<string> split;
@@ -1141,7 +1139,7 @@ vector<string> StringSplit(string const &s, std::string const &sep,
       split.push_back(s.substr(start, pos-start));
       
       // if maxsplit is reached, the remaining string is the last item
-      if(maxsplit > 0 && split.size() >= maxsplit)
+      if(split.size() >= maxsplit)
       {
          split[split.size()-1] = s.substr(start);
          break;
index 080f9f82eb6011dc13180571063703cddac23c3d..b42e0649171ceae71131f3236132af199a53d400 100644 (file)
@@ -17,7 +17,7 @@
 #define STRUTL_H
 
 
-
+#include <limits>
 #include <stdlib.h>
 #include <string>
 #include <cstring>
@@ -70,8 +70,23 @@ bool TokSplitString(char Tok,char *Input,char **List,
 // split a given string by a char
 std::vector<std::string> VectorizeString(std::string const &haystack, char const &split) __attrib_const;
 
-// split a given string by a string token
-std::vector<std::string> StringSplit(std::string const &input, std::string const &sep, unsigned int maxsplit=0) __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);
index b044b7f341469e2f12f4c5d914fb25e0283fa530..110a20d277dd49ecb7f747e704fa9433c2621e4b 100644 (file)
@@ -65,5 +65,9 @@ int main(int argc,char *argv[])
    equals(result[0], "x");
    equals(result[1], "y:z");
 
+   input = "abc";
+   result = StringSplit(input, "");
+   equals(result.size(), 0);
+
    return 0;
 }