]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: add str_join helper
authorSage Weil <sage@inktank.com>
Thu, 15 Aug 2013 21:36:49 +0000 (14:36 -0700)
committerSage Weil <sage@inktank.com>
Thu, 15 Aug 2013 21:36:49 +0000 (14:36 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
src/include/str_list.h

index 8549c4f21ce8a8a621a3788968ed51a9fd2d56f2..83a0e64e135b1b56d3b9ecdb46d3ad7498575849 100644 (file)
@@ -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