diff options
author | Peter Powell <petpow@saberuk.com> | 2018-07-26 21:23:45 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2018-07-26 21:41:36 +0100 |
commit | 9cf448a332799a138dad0acb5b2878535770571d (patch) | |
tree | 4d922164f102e1dbf98aa3261e77da305664f532 /include | |
parent | 384ef31bc01e4a1a2e59d082c9066002410ba54a (diff) |
Replace irc::stringjoiner with a generic stdalgo::string::join.
This can also be used with different types of collection containing
values which are not a string.
Diffstat (limited to 'include')
-rw-r--r-- | include/hashcomp.h | 7 | ||||
-rw-r--r-- | include/inspircd.h | 2 | ||||
-rw-r--r-- | include/stdalgo.h | 19 |
3 files changed, 20 insertions, 8 deletions
diff --git a/include/hashcomp.h b/include/hashcomp.h index bda85182f..71f900654 100644 --- a/include/hashcomp.h +++ b/include/hashcomp.h @@ -108,13 +108,6 @@ namespace irc bool CoreExport operator()(const std::string& a, const std::string& b) const; }; - /** Joins the contents of a vector to a string. - * @param sequence Zero or more items to join. - * @param separator The character to place between the items, defaults to ' ' (space). - * @return Joined string. - */ - std::string CoreExport stringjoiner(const std::vector<std::string>& sequence, char separator = ' '); - /** irc::sepstream allows for splitting token seperated lists. * Each successive call to sepstream::GetToken() returns * the next token, until none remain, at which point the method returns diff --git a/include/inspircd.h b/include/inspircd.h index 7180fd672..00093e52b 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -50,6 +50,7 @@ #include "compat.h" #include "aligned_storage.h" #include "typedefs.h" +#include "convto.h" #include "stdalgo.h" CoreExport extern InspIRCd* ServerInstance; @@ -66,7 +67,6 @@ struct fakederef }; #include "config.h" -#include "convto.h" #include "dynref.h" #include "consolecolors.h" #include "cull_list.h" diff --git a/include/stdalgo.h b/include/stdalgo.h index f4465963a..bb5e12262 100644 --- a/include/stdalgo.h +++ b/include/stdalgo.h @@ -95,6 +95,25 @@ namespace stdalgo return (!strcasecmp(tocstr(str1), tocstr(str2))); } + /** Joins the contents of a vector to a string. + * @param sequence Zero or more items to join. + * @param separator The character to place between the items, defaults to ' ' (space). + * @return The joined string. + */ + template<typename Collection> + inline std::string join(const Collection& sequence, char separator = ' ') + { + std::string joined; + if (sequence.empty()) + return joined; + + for (typename Collection::const_iterator iter = sequence.begin(); iter != sequence.end(); ++iter) + joined.append(ConvToStr(*iter)).push_back(separator); + + joined.erase(joined.end() - 1); + return joined; + } + /** Replace first occurrence of a substring ('target') in a string ('str') with another string ('replacement'). * @param str String to perform replacement in * @param target String to replace |