From c965b45bcd915ce92943fd4d436b5bd790f0442f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20Kl=C3=B6cker?= Date: Mon, 4 Apr 2022 13:09:07 +0200 Subject: [PATCH] cpp: Add internal utility function for splitting strings * lang/cpp/src/util.h (split): New. -- This function splits a given string using the given delimiter into several strings. GnuPG-bug-id: 5904 --- lang/cpp/src/util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lang/cpp/src/util.h b/lang/cpp/src/util.h index b6f9ca50..423973a8 100644 --- a/lang/cpp/src/util.h +++ b/lang/cpp/src/util.h @@ -177,6 +177,19 @@ static inline gpgme_sig_notation_flags_t add_to_gpgme_sig_notation_flags_t(unsi return static_cast(result); } +static inline std::vector split(const std::string &text, char delimiter) +{ + std::vector result; + if (!text.empty()) { + std::istringstream stream{text}; + std::string line; + while (std::getline(stream, line, delimiter)) { + result.push_back(line); + } + } + return result; +} + /** * Adapter for passing a vector of strings as NULL-terminated array of * const char* to the C-interface of gpgme.