diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-15 04:26:08 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-15 04:26:08 +0200 |
commit | 001804edef29549dc49b2adf6bab88cd7f24760a (patch) | |
tree | bb75ae54b21e265383f24cc3cecae4c394a9cdda /utils/stringlib.h | |
parent | 244971287003d079e46193b8a209c28955f90134 (diff) | |
parent | b4ce7c0b51d8615abf84c022ec3a981bee3277fe (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils/stringlib.h')
-rw-r--r-- | utils/stringlib.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/utils/stringlib.h b/utils/stringlib.h index 2fdbfff8..aadec93c 100644 --- a/utils/stringlib.h +++ b/utils/stringlib.h @@ -16,6 +16,8 @@ #include <sstream> #include <algorithm> +#include "string_piece.hh" + namespace { const char c_isspace[]=" \t\n\r\f\v"; // somewhat ridiculous, including characters nobody uses. const char common_isspace[]=" \t\n\r"; // even \n\r is borderline, but maybe you pass multiline DOS format text. @@ -221,6 +223,21 @@ void VisitTokens(char *p,char *const end,F f) { } } +inline std::vector<StringPiece> TokenizeMultisep(const StringPiece& text, const StringPiece& separator) { + std::vector<StringPiece> res; + size_t cur = 0; + while(cur < text.size()) { + const auto n = text.find(separator, cur); + if (n == StringPiece::npos) { + res.push_back(text.substr(cur)); + break; + } + res.push_back(text.substr(cur, n - cur)); + cur = n + separator.size(); + } + return res; +} + template <class F> void VisitTokens(char *p,F f) { VisitTokens(p,p+std::strlen(p),f); |