overload join_string() for std::set
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 19 Jul 2018 09:02:53 +0000 (11:02 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 2 Aug 2018 12:31:20 +0000 (14:31 +0200)
src/stringfunc.cpp
src/stringfunc.hxx

index 72de728..a8c501b 100644 (file)
@@ -479,6 +479,29 @@ std::string join_string(
    return result;
 } // eo join_string(const std::vector< std::string >&,const std::string&)
 
+/** @brief same as join_string for list, except uses a set */
+std::string join_string(
+   const std::set< std::string >& parts,
+   const std::string& delimiter
+)
+{
+   std::string result;
+
+   if (! parts.empty() )
+   {
+       BOOST_FOREACH(const std::string &part, parts)
+       {
+           if (!result.empty ())
+           {
+               result += delimiter;
+           }
+           result += part;
+       }
+   }
+
+   return result;
+} // eo join_string(const std::vector< std::string >&,const std::string&)
+
 std::string join_string (
    const char *const parts[], /* assumed NULL-terminated */
    const std::string& delimiter
index 6acfa32..29b8aba 100644 (file)
@@ -35,6 +35,7 @@ on this file might be covered by the GNU General Public License.
 #define __STRINGFUNC_HXX
 
 #include <list>
+#include <set>
 #include <vector>
 #include <string>
 #include <sstream>
@@ -141,6 +142,11 @@ std::string join_string(
 );
 
 std::string join_string(
+   const std::set< std::string >& parts,
+   const std::string& delimiter = "\n"
+);
+
+std::string join_string(
    const char *const parts [],
    const std::string& delimiter = "\n"
 );