From 0aaf13b5ceca72f044e9f4c4780a353dba9bcdac Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 19 Jul 2018 11:02:53 +0200 Subject: [PATCH] overload join_string() for std::set --- src/stringfunc.cpp | 23 +++++++++++++++++++++++ src/stringfunc.hxx | 6 ++++++ 2 files changed, 29 insertions(+), 0 deletions(-) diff --git a/src/stringfunc.cpp b/src/stringfunc.cpp index 72de728..a8c501b 100644 --- a/src/stringfunc.cpp +++ b/src/stringfunc.cpp @@ -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 diff --git a/src/stringfunc.hxx b/src/stringfunc.hxx index 6acfa32..29b8aba 100644 --- a/src/stringfunc.hxx +++ b/src/stringfunc.hxx @@ -35,6 +35,7 @@ on this file might be covered by the GNU General Public License. #define __STRINGFUNC_HXX #include +#include #include #include #include @@ -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" ); -- 1.7.1