]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/strutl.cc
fix libapt-inst for >2G debs (closes: #725483)
[apt.git] / apt-pkg / contrib / strutl.cc
index d06637155b48e7ea8977f1e7cbc5006ed01351af..77e48962c086ec7be659736b1fd6e9d62e303994 100644 (file)
@@ -943,6 +943,8 @@ bool StrToTime(const string &Val,time_t &Result)
    Tm.tm_isdst = 0;
    if (Month[0] != 0)
       Tm.tm_mon = MonthConv(Month);
+   else
+      Tm.tm_mon = 0; // we don't have a month, so pick something
    Tm.tm_year -= 1900;
    
    // Convert to local time and then to GMT
@@ -1116,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                                /*{{{*/
 // ---------------------------------------------------------------------
 /* */