diff options
author | Sage Weil <sage@inktank.com> | 2013-08-15 14:36:49 -0700 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2013-08-15 14:38:09 -0700 |
commit | d212bba6bd0d7d234097122988e4d973064b5645 (patch) | |
tree | 29afbf56faa770c7ceb6e71bc116422a407e8749 | |
parent | a99fef9189086f5dd6ddacaecf967619dc5fe407 (diff) | |
download | ceph-d212bba6bd0d7d234097122988e4d973064b5645.tar.gz |
common: add str_join helper
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
(cherry picked from commit ce3a0944d9b47f7b178fe7775c9d105305b238e0)
-rw-r--r-- | src/include/str_list.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/include/str_list.h b/src/include/str_list.h index 8549c4f21ce..83a0e64e135 100644 --- a/src/include/str_list.h +++ b/src/include/str_list.h @@ -1,9 +1,10 @@ #ifndef CEPH_STRLIST_H #define CEPH_STRLIST_H -#include <string> #include <list> #include <set> +#include <sstream> +#include <string> #include <vector> extern void get_str_list(const std::string& str, @@ -22,5 +23,17 @@ extern void get_str_set(const std::string& str, const char *delims, std::set<std::string>& str_list); +inline std::string str_join(const std::vector<std::string>& v, std::string sep) +{ + if (v.empty()) + return std::string(); + std::vector<std::string>::const_iterator i = v.begin(); + std::string r = *i; + for (++i; i != v.end(); ++i) { + r += sep; + r += *i; + } + return r; +} #endif |