diff options
author | Ingo Klöcker <[email protected]> | 2022-04-04 11:09:07 +0000 |
---|---|---|
committer | Ingo Klöcker <[email protected]> | 2022-04-05 08:05:43 +0000 |
commit | c965b45bcd915ce92943fd4d436b5bd790f0442f (patch) | |
tree | f2ea346bc195cfe059893703bc198be3746d4f91 | |
parent | cpp: Do not export symbols of the Private class (diff) | |
download | gpgme-c965b45bcd915ce92943fd4d436b5bd790f0442f.tar.gz gpgme-c965b45bcd915ce92943fd4d436b5bd790f0442f.zip |
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
-rw-r--r-- | lang/cpp/src/util.h | 13 |
1 files changed, 13 insertions, 0 deletions
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<gpgme_sig_notation_flags_t>(result); } +static inline std::vector<std::string> split(const std::string &text, char delimiter) +{ + std::vector<std::string> 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. |