Added join function for strings
This commit is contained in:
parent
1e29151974
commit
542a5ee3d8
|
@ -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);
|
||||||
|
|
||||||
|
@ -15,4 +16,16 @@ 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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue