{"id":3119,"url":"https://patchwork.libcamera.org/api/patches/3119/?format=json","web_url":"https://patchwork.libcamera.org/patch/3119/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200316214310.27665-3-laurent.pinchart@ideasonboard.com>","date":"2020-03-16T21:43:02","name":"[libcamera-devel,v2,02/10] libcamera: utils: Add string join function","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"23aa4f8a18cfb59774bf392f8d2dfc45b87103b4","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/3119/mbox/","series":[{"id":724,"url":"https://patchwork.libcamera.org/api/series/724/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=724","date":"2020-03-16T21:43:00","name":"Simple pipeline handler","version":2,"mbox":"https://patchwork.libcamera.org/series/724/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/3119/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/3119/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A6E7960422\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 16 Mar 2020 22:43:21 +0100 (CET)","from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E6008FC9;\n\tMon, 16 Mar 2020 22:43:20 +0100 (CET)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584395001;\n\tbh=FzmzqD4WiUI/9NFharnzhuMQCc1MhFQbgM2nIQOaTtw=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qh8PqRQHSg3EUrY1axvtkIGpS0mvKN8A2VRxRfGokwUOMPJ4SIP7ZtFMHTRPTAAFT\n\tejU1EPYpPNBztVSREAMq5ImpVZJwr/ERoplPgXFXJSB2Mwv/u9aYvr044kE79RuJnL\n\t/4thK+Xp1eAwCHoIq/JLlSlK5PELpHHCEdZaA7HY=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Martijn Braam <martijn@brixit.nl>, Mickael GUENE <mickael.guene@st.com>, \n\tBenjamin GAIGNARD <benjamin.gaignard@st.com>,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>","Date":"Mon, 16 Mar 2020 23:43:02 +0200","Message-Id":"<20200316214310.27665-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.24.1","In-Reply-To":"<20200316214310.27665-1-laurent.pinchart@ideasonboard.com>","References":"<20200316214310.27665-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 02/10] libcamera: utils: Add string\n\tjoin function","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 16 Mar 2020 21:43:21 -0000"},"content":"Add a utils::join() function to join elements of a container into a\nstring, with a separator and an optional conversion function if the\nelements are not implicitly convertible to std::string.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/include/utils.h | 44 +++++++++++++++++++++++++++++++++++\n src/libcamera/utils.cpp       | 16 +++++++++++++\n test/utils.cpp                |  7 +++++-\n 3 files changed, 66 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/include/utils.h b/src/libcamera/include/utils.h\nindex 940597760ee2..74ceed760cb3 100644\n--- a/src/libcamera/include/utils.h\n+++ b/src/libcamera/include/utils.h\n@@ -11,6 +11,7 @@\n #include <chrono>\n #include <memory>\n #include <ostream>\n+#include <sstream>\n #include <string>\n #include <string.h>\n #include <sys/time.h>\n@@ -109,6 +110,49 @@ inline _hex hex<uint64_t>(uint64_t value, unsigned int width)\n \n size_t strlcpy(char *dst, const char *src, size_t size);\n \n+#ifndef __DOXYGEN__\n+template<typename Container, typename UnaryOp>\n+std::string join(const Container &items, const std::string &sep, UnaryOp op)\n+{\n+\tstd::ostringstream ss;\n+\tbool first = true;\n+\n+\tfor (typename Container::const_iterator it = std::begin(items);\n+\t     it != std::end(items); ++it) {\n+\t\tif (!first)\n+\t\t\tss << sep;\n+\t\telse\n+\t\t\tfirst = false;\n+\n+\t\tss << op(*it);\n+\t}\n+\n+\treturn ss.str();\n+}\n+\n+template<typename Container>\n+std::string join(const Container &items, const std::string &sep)\n+{\n+\tstd::ostringstream ss;\n+\tbool first = true;\n+\n+\tfor (typename Container::const_iterator it = std::begin(items);\n+\t     it != std::end(items); ++it) {\n+\t\tif (!first)\n+\t\t\tss << sep;\n+\t\telse\n+\t\t\tfirst = false;\n+\n+\t\tss << *it;\n+\t}\n+\n+\treturn ss.str();\n+}\n+#else\n+template<typename Container, typename UnaryOp>\n+std::string join(const Container &items, const std::string &sep, UnaryOp op = nullptr);\n+#endif\n+\n namespace details {\n \n class StringSplitter\ndiff --git a/src/libcamera/utils.cpp b/src/libcamera/utils.cpp\nindex f566e88cec5b..1d0e583756cf 100644\n--- a/src/libcamera/utils.cpp\n+++ b/src/libcamera/utils.cpp\n@@ -291,6 +291,22 @@ details::StringSplitter::iterator details::StringSplitter::end() const\n \treturn iterator(this, std::string::npos);\n }\n \n+/**\n+ * \\fn template<typename Container, typename UnaryOp> \\\n+ * std::string utils::join(const Container &items, const std::string &sep, UnaryOp op)\n+ * \\brief Join elements of a container in a string with a separator\n+ * \\param[in] items The container\n+ * \\param[in] sep The separator to add between elements\n+ * \\param[in] op A function that converts individual elements to strings\n+ *\n+ * This function joins all elements in the \\a items container into a string and\n+ * returns it. The \\a sep separator is added between elements. If the container\n+ * elements are not implicitly convertible to std::string, the \\a op function\n+ * shall be provided to perform conversion of elements to std::string.\n+ *\n+ * \\return A string that concatenates all elements in the container\n+ */\n+\n /**\n  * \\fn split(const std::string &str, const std::string &delim)\n  * \\brief Split a string based on a delimiter\ndiff --git a/test/utils.cpp b/test/utils.cpp\nindex 58816f153066..2fca89ef3278 100644\n--- a/test/utils.cpp\n+++ b/test/utils.cpp\n@@ -99,7 +99,7 @@ protected:\n \t\t\treturn TestFail;\n \t\t}\n \n-\t\t/* utils::split() test. */\n+\t\t/* utils::join() and utils::split() test. */\n \t\tstd::vector<std::string> elements = {\n \t\t\t\"/bin\",\n \t\t\t\"/usr/bin\",\n@@ -111,6 +111,11 @@ protected:\n \t\tfor (const auto &element : elements)\n \t\t\tpath += (path.empty() ? \"\" : \":\") + element;\n \n+\t\tif (path != utils::join(elements, \":\")) {\n+\t\t\tcerr << \"utils::join() test failed\" << endl;\n+\t\t\treturn TestFail;\n+\t\t}\n+\n \t\tstd::vector<std::string> dirs;\n \n \t\tfor (const auto &dir : utils::split(path, \":\"))\n","prefixes":["libcamera-devel","v2","02/10"]}