diff options
author | Julian Andres Klode <jak@debian.org> | 2017-01-17 00:07:09 +0100 |
---|---|---|
committer | Julian Andres Klode <jak@debian.org> | 2017-01-17 00:07:09 +0100 |
commit | c5b8afab0f409b06a63599ff1c5acb433f3957d4 (patch) | |
tree | 473ea8d659e6397b69c7445ca67faa51a9e441d4 /apt-pkg | |
parent | 5d47d9b8f8a43f2b7502336a1df4e017fbf1602d (diff) |
strutl: Provide an APT::String::Join() function
Thanks: James Clarke <jrtc27@jrtc27.com> for the implementation
Gbp-Dch: ignore
Diffstat (limited to 'apt-pkg')
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 12 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index cf8feb970..da0121eca 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -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(); +} + } } /*}}}*/ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 918ac89c7..73f27aa6c 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -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); + } } |