From c5b8afab0f409b06a63599ff1c5acb433f3957d4 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 17 Jan 2017 00:07:09 +0100 Subject: strutl: Provide an APT::String::Join() function Thanks: James Clarke for the implementation Gbp-Dch: ignore --- apt-pkg/contrib/strutl.cc | 12 ++++++++++++ apt-pkg/contrib/strutl.h | 2 ++ 2 files changed, 14 insertions(+) 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 #include #include +#include #include #include @@ -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 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 list, const std::string &sep); + } } -- cgit v1.2.3