Added join function for strings

This commit is contained in:
Daniel Wolf 2016-06-14 17:38:41 +02:00
parent 1e29151974
commit 542a5ee3d8
1 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,7 @@
#include <vector> #include <vector>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/lexical_cast.hpp>
std::vector<std::string> splitIntoLines(const std::string& s); std::vector<std::string> splitIntoLines(const std::string& s);
@ -16,3 +17,15 @@ boost::optional<char> toASCII(char32_t ch);
std::string toASCII(const std::u32string& s); std::string toASCII(const std::u32string& s);
std::u32string utf8ToUtf32(const std::string& s); std::u32string utf8ToUtf32(const std::string& s);
template<typename T>
std::string join(T range, const std::string separator) {
std::string result;
bool isFirst = true;
for (const auto& element : range) {
if (!isFirst) result.append(separator);
isFirst = false;
result.append(boost::lexical_cast<std::string>(element));
}
return result;
}