Просмотр исходного кода

change maxsplit default from "0" to maxint

Michael Vogt лет назад: 12
Родитель
Сommit
2ddab3fb95
3 измененных файлов с 7 добавлено и 3 удалено
  1. 1 1
      apt-pkg/contrib/strutl.cc
  2. 2 2
      apt-pkg/contrib/strutl.h
  3. 4 0
      test/libapt/strutil_test.cc

+ 1 - 1
apt-pkg/contrib/strutl.cc

@@ -1139,7 +1139,7 @@ vector<string> StringSplit(std::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;

+ 2 - 2
apt-pkg/contrib/strutl.h

@@ -17,7 +17,7 @@
 #define STRUTL_H
 
 
-
+#include <limits>
 #include <stdlib.h>
 #include <string>
 #include <cstring>
@@ -86,7 +86,7 @@ std::vector<std::string> VectorizeString(std::string const &haystack, char const
  */
 std::vector<std::string> StringSplit(std::string const &input, 
                                      std::string const &sep, 
-                                     unsigned int maxsplit=0) __attrib_const;
+                                     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);

+ 4 - 0
test/libapt/strutil_test.cc

@@ -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;
 }