aboutsummaryrefslogtreecommitdiff
path: root/src/util/spanparsing.h
diff options
context:
space:
mode:
authorSebastian Falbesoner <sebastian.falbesoner@gmail.com>2021-09-11 13:02:47 +0200
committerSebastian Falbesoner <sebastian.falbesoner@gmail.com>2022-04-11 22:19:46 +0200
commit9cc8e876e412056ed22d364538f0da3d5d71946d (patch)
treecf30bf1d489e1bd7a37274deedf06fe60fb175b4 /src/util/spanparsing.h
parent2b5a741e98f186e50d9fbe1ceadcc8b8c91547f7 (diff)
refactor: introduce single-separator split helper `SplitString`
This helper uses spanparsing::Split internally and enables to replace all calls to boost::split where only a single separator is passed. Co-authored-by: Martin Ankerl <Martin.Ankerl@gmail.com> Co-authored-by: MarcoFalke <falke.marco@gmail.com>
Diffstat (limited to 'src/util/spanparsing.h')
-rw-r--r--src/util/spanparsing.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/util/spanparsing.h b/src/util/spanparsing.h
index fa2e698e6d..ebec8714a7 100644
--- a/src/util/spanparsing.h
+++ b/src/util/spanparsing.h
@@ -43,7 +43,22 @@ Span<const char> Expr(Span<const char>& sp);
* Note that this function does not care about braces, so splitting
* "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.
*/
-std::vector<Span<const char>> Split(const Span<const char>& sp, char sep);
+template <typename T = Span<const char>>
+std::vector<T> Split(const Span<const char>& sp, char sep)
+{
+ std::vector<T> ret;
+ auto it = sp.begin();
+ auto start = it;
+ while (it != sp.end()) {
+ if (*it == sep) {
+ ret.emplace_back(start, it);
+ start = it + 1;
+ }
+ ++it;
+ }
+ ret.emplace_back(start, it);
+ return ret;
+}
} // namespace spanparsing