88#include < span.h>
99
1010#include < string>
11+ #include < string_view>
1112#include < vector>
1213
1314namespace spanparsing {
@@ -36,21 +37,21 @@ bool Func(const std::string& str, Span<const char>& sp);
3637 */
3738Span<const char > Expr (Span<const char >& sp);
3839
39- /* * Split a string on every instance of sep , returning a vector.
40+ /* * Split a string on any char found in separators , returning a vector.
4041 *
4142 * If sep does not occur in sp, a singleton with the entirety of sp is returned.
4243 *
4344 * Note that this function does not care about braces, so splitting
4445 * "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.
4546 */
4647template <typename T = Span<const char >>
47- std::vector<T> Split (const Span<const char >& sp, char sep )
48+ std::vector<T> Split (const Span<const char >& sp, std::string_view separators )
4849{
4950 std::vector<T> ret;
5051 auto it = sp.begin ();
5152 auto start = it;
5253 while (it != sp.end ()) {
53- if (*it == sep ) {
54+ if (separators. find ( *it) != std::string::npos ) {
5455 ret.emplace_back (start, it);
5556 start = it + 1 ;
5657 }
@@ -60,6 +61,19 @@ std::vector<T> Split(const Span<const char>& sp, char sep)
6061 return ret;
6162}
6263
64+ /* * Split a string on every instance of sep, returning a vector.
65+ *
66+ * If sep does not occur in sp, a singleton with the entirety of sp is returned.
67+ *
68+ * Note that this function does not care about braces, so splitting
69+ * "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.
70+ */
71+ template <typename T = Span<const char >>
72+ std::vector<T> Split (const Span<const char >& sp, char sep)
73+ {
74+ return Split<T>(sp, std::string_view{&sep, 1 });
75+ }
76+
6377} // namespace spanparsing
6478
6579#endif // BITCOIN_UTIL_SPANPARSING_H
0 commit comments