Patch Detail
Show a patch.
GET /api/1.1/patches/3086/?format=api
{ "id": 3086, "url": "https://patchwork.libcamera.org/api/1.1/patches/3086/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3086/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200313233856.25202-3-laurent.pinchart@ideasonboard.com>", "date": "2020-03-13T23:38:50", "name": "[libcamera-devel,2/8] 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/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3086/mbox/", "series": [ { "id": 718, "url": "https://patchwork.libcamera.org/api/1.1/series/718/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=718", "date": "2020-03-13T23:38:48", "name": "Simple pipeline handler", "version": 1, "mbox": "https://patchwork.libcamera.org/series/718/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3086/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3086/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 0CB4C62930\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 14 Mar 2020 00:39:06 +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 6779A1367;\n\tSat, 14 Mar 2020 00:39:05 +0100 (CET)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1584142745;\n\tbh=J0c2nfJFXlI6E4sVzYJWTGJhC6/tlaySqex0A1Ia7Ck=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=s0n9IkkV33XCJVAO1ILOQXCMuAQylc1h1Ve11XwYrel0LH1twyzBZazuvZlkp7ia7\n\tNdhuo9vp4F9HL83WfksGWRNVRKO4nQEUjW5+dA4lqLxDtcrIXgjI/1IxzKoHsz+zri\n\tNATDfg+eDPHW+O6VI24f9s7BmXH8QPLx5y6Fgu/g=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Martijn Braam <martijn@brixit.nl>,\n\tAndrey Konovalov <andrey.konovalov@linaro.org>,\n\tMickael GUENE <mickael.guene@st.com>,\n\tBenjamin GAIGNARD <benjamin.gaignard@st.com>", "Date": "Sat, 14 Mar 2020 01:38:50 +0200", "Message-Id": "<20200313233856.25202-3-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.24.1", "In-Reply-To": "<20200313233856.25202-1-laurent.pinchart@ideasonboard.com>", "References": "<20200313233856.25202-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 2/8] libcamera: utils: Add string join\n\tfunction", "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": "Fri, 13 Mar 2020 23:39:06 -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>\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", "2/8" ] }