add templated version of join_strings

develop
Myk Taylor 2023-02-24 17:05:08 -08:00
parent 816371ca69
commit a684f294c5
No known key found for this signature in database
GPG Key ID: 8A39CA0FA0C16E78
2 changed files with 16 additions and 2 deletions

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

@ -404,6 +404,22 @@ DFHACK_EXPORT bool split_string(std::vector<std::string> *out,
bool squash_empty = false); bool squash_empty = false);
DFHACK_EXPORT std::string join_strings(const std::string &separator, const std::vector<std::string> &items); 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 toUpper(const std::string &str);
DFHACK_EXPORT std::string toLower(const std::string &str); DFHACK_EXPORT std::string toLower(const std::string &str);
DFHACK_EXPORT std::string to_search_normalized(const std::string &str); DFHACK_EXPORT std::string to_search_normalized(const std::string &str);