From 41053d721ce7f81652d7e873067376b94f9a060d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 1 Oct 2013 12:03:37 +0200 Subject: improve documentation for StringSplit() --- apt-pkg/contrib/strutl.cc | 6 ++---- apt-pkg/contrib/strutl.h | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index fd768f183..96c6d2f35 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1120,11 +1120,9 @@ vector 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 StringSplit(string const &s, std::string const &sep, +vector StringSplit(std::string const &s, std::string const &sep, unsigned int maxsplit) { vector split; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 080f9f82e..eb47287a4 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -70,8 +70,23 @@ bool TokSplitString(char Tok,char *Input,char **List, // split a given string by a char std::vector VectorizeString(std::string const &haystack, char const &split) __attrib_const; -// split a given string by a string token -std::vector 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 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); -- cgit v1.2.3 From 2ddab3fb958518acbd26685eeeb7755106b721a3 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 1 Oct 2013 12:38:03 +0200 Subject: change maxsplit default from "0" to maxint --- apt-pkg/contrib/strutl.cc | 2 +- apt-pkg/contrib/strutl.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 96c6d2f35..77e48962c 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -1139,7 +1139,7 @@ vector 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; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index eb47287a4..b42e06491 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -17,7 +17,7 @@ #define STRUTL_H - +#include #include #include #include @@ -86,7 +86,7 @@ std::vector VectorizeString(std::string const &haystack, char const */ std::vector StringSplit(std::string const &input, std::string const &sep, - unsigned int maxsplit=0) __attrib_const; + unsigned int maxsplit=std::numeric_limits::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); -- cgit v1.2.3