util::Split

Split a string on any char found in separators, returning a vector.

Synopsis

Declared in <util/string.h>

template<typename T = std::span<char const>>
std::vector<T>
Split(
    std::span<char const> const& sp,
    std::string_view separators,
    bool include_sep = false);

Description

If sep does not occur in sp, a singleton with the entirety of sp is returned.

Note that this function does not care about braces, so splitting "foo(bar(1),2),3) on ',' will return {"foo(bar(1)", "2)", "3)"}.

If include_sep == true, splitting "foo(bar(1),2),3) on ',' will return:

  • foo(bar(1),

  • 2),

  • 3)

Return Value

The pieces of sp between separators.

Parameters

NameDescription
include_sep [in]Whether to include the separator at the end of the left side of the splits.
sp [in]The input character range to split.
separators [in]Set of characters, any of which splits the input.