add join_words() utility function

This commit is contained in:
Axel Kohlmeyer
2022-07-04 18:26:59 -04:00
parent e13027787b
commit de08609634
3 changed files with 27 additions and 0 deletions

View File

@ -984,6 +984,19 @@ size_t utils::trim_and_count_words(const std::string &text, const std::string &s
return utils::count_words(trim_comment(text), separators);
}
/* ----------------------------------------------------------------------
combine words in vector to single string with separator added between words
------------------------------------------------------------------------- */
std::string utils::join_words(const std::vector<std::string> &words, const std::string &sep)
{
std::string result;
if (words.size() > 0) result = words[0];
for (std::size_t i = 1; i < words.size(); ++i) result += sep + words[i];
return result;
}
/* ----------------------------------------------------------------------
Convert string into words on whitespace while handling single and
double quotes.