X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fstdalgo.h;h=bb5e122623277a9daa60a6ecd13a82852db74ed1;hb=9cf448a332799a138dad0acb5b2878535770571d;hp=f4465963a65f5bd0884831d647ca5f4ffea65799;hpb=a3e0768758ca68429a29d9c78ce672f2d938c6e7;p=user%2Fhenk%2Fcode%2Finspircd.git 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 + 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