]> git.saurik.com Git - apt.git/commitdiff
doc update
authorMichael Vogt <mvo@debian.org>
Sat, 7 Sep 2013 14:16:49 +0000 (16:16 +0200)
committerMichael Vogt <mvo@debian.org>
Sat, 7 Sep 2013 14:16:49 +0000 (16:16 +0200)
apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h

index 508af8922b0c87c4d4eb17274c5df8e15b01310b..fd768f18328371b98138bbcb44ff777fdc195478 100644 (file)
@@ -1118,10 +1118,11 @@ vector<string> 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<string> StringSplit(string const &s, std::string const &sep,
                            unsigned int maxsplit)
@@ -1129,22 +1130,24 @@ vector<string> StringSplit(string const &s, std::string const &sep,
    vector<string> 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;
 }
                                                                        /*}}}*/
index 944f91403c7e1597bbd9c2be84cc63fdb91a11fe..080f9f82eb6011dc13180571063703cddac23c3d 100644 (file)
@@ -62,11 +62,17 @@ 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;
-// like python string.split
-std::vector<std::string> StringSplit(std::string const &haystack, std::string const &sep, unsigned int maxsplit=0) __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;
+
 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);