Merge pull request #2947 from myk002/myk_join_strings

[MiscUtils] add templated version of join_strings
develop
Myk 2023-02-26 09:22:56 -08:00 committed by GitHub
commit ff464c4746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

@ -60,8 +60,6 @@ distribution.
#include "LuaTools.h"
#include "DFHackVersion.h"
#include "MiscUtils.h"
using namespace DFHack;
#include "df/plotinfost.h"

@ -404,6 +404,22 @@ DFHACK_EXPORT bool split_string(std::vector<std::string> *out,
bool squash_empty = false);
DFHACK_EXPORT std::string join_strings(const std::string &separator, const std::vector<std::string> &items);
template<typename T>
inline std::string join_strings(const std::string &separator, T &items) {
std::stringstream ss;
bool first = true;
for (auto &item : items) {
if (first)
first = false;
else
ss << separator;
ss << item;
}
return ss.str();
}
DFHACK_EXPORT std::string toUpper(const std::string &str);
DFHACK_EXPORT std::string toLower(const std::string &str);
DFHACK_EXPORT std::string to_search_normalized(const std::string &str);