X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstrings%2Futils.h;h=f7e9433fd2d07a3e7496e7e7735af77d5dfff4c0;hp=2040bcd36fae3fa7f947709045db9e6624afd5fe;hb=9955efca718d8be72b63c7c2182ca59e7b9d0935;hpb=c7afef88380ebebc8c2b04e48664d73281ec8848 diff --git a/source/strings/utils.h b/source/strings/utils.h index 2040bcd..f7e9433 100644 --- a/source/strings/utils.h +++ b/source/strings/utils.h @@ -56,17 +56,19 @@ std::vector split_fields(const std::string &str, const std::string separators will cause an empty string to be placed in the result. */ std::vector split_fields(const std::string &str, char sep, int max_split = -1); +/** Appends a string to another, using a separator if both are non-empty. */ +std::string &append(std::string &str, const std::string &sep, const std::string &other); + +/** Joins two strings, using a separator if both are non-empty. */ +std::string join(const std::string &str1, const std::string &sep, const std::string &str2); + /** Concatenates strings from an iterator range. */ template std::string join(Iter begin, Iter end, const std::string &sep = " ") { std::string result; for(Iter i=begin; i!=end; ++i) - { - if(i!=begin) - result += sep; - result += *i; - } + append(result, sep, *i); return result; }