]> git.saurik.com Git - apt.git/commitdiff
strutl: Provide an APT::String::Join() function
authorJulian Andres Klode <jak@debian.org>
Mon, 16 Jan 2017 23:07:09 +0000 (00:07 +0100)
committerJulian Andres Klode <jak@debian.org>
Mon, 16 Jan 2017 23:07:09 +0000 (00:07 +0100)
Thanks: James Clarke <jrtc27@jrtc27.com> for the implementation
Gbp-Dch: ignore

apt-pkg/contrib/strutl.cc
apt-pkg/contrib/strutl.h

index cf8feb970a102883908d3f83cc9aaf0983d9bc97..da0121eca9341689f7e79e59c7a1c33eeab9aaba 100644 (file)
@@ -27,6 +27,7 @@
 #include <locale>
 #include <sstream>
 #include <string>
+#include <sstream>
 #include <vector>
 
 #include <stddef.h>
@@ -85,6 +86,17 @@ bool Startswith(const std::string &s, const std::string &start)
    return (s.compare(0, start.size(), start) == 0);
 }
 
+std::string Join(std::vector<std::string> list, const std::string &sep)
+{
+   std::ostringstream oss;
+   for (auto it = list.begin(); it != list.end(); it++)
+   {
+      if (it != list.begin()) oss << sep;
+      oss << *it;
+   }
+   return oss.str();
+}
+
 }
 }
                                                                        /*}}}*/
index 918ac89c741832f41a00117bf006d86ccc00e827..73f27aa6c3d8840ab05e6b923f5cbcd80a7ac977 100644 (file)
@@ -44,6 +44,8 @@ namespace APT {
       std::string Strip(const std::string &s);
       bool Endswith(const std::string &s, const std::string &ending);
       bool Startswith(const std::string &s, const std::string &starting);
+      std::string Join(std::vector<std::string> list, const std::string &sep);
+
    }
 }