![]() |
General Utility Library for C++17 25.4.1
|
Split a string into substrings.
Functions | |
template<typename StringContainer = std::vector<std::string>, typename ContainerInsertFct = void (*)(StringContainer&, std::string_view)> | |
StringContainer | gul17::tokenize (std::string_view str, std::string_view delimiters=default_whitespace_characters, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string. | |
template<typename StringContainer = std::vector<std::string_view>, typename ContainerInsertFct = void (*)(StringContainer&, std::string_view)> | |
StringContainer | gul17::tokenize_sv (std::string_view str, std::string_view delimiters=default_whitespace_characters, ContainerInsertFct insert_fct=detail::emplace_back< StringContainer >) |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string. | |
|
inline |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string.
Multiple adjacent delimiters are treated like a single one, and delimiters at the beginning and end of the string are ignored. For example, tokenize(" A B C ") yields a vector with the three entries "A", "B", and "C".
This function returns a std::vector<std::string>
by default, but a compatible container for string/string_view types can be specified via a template parameter:
StringContainer | A container for strings or std::string_view-like types, e.g. std::vector<std::string> or std::list<std::string_view> |
ContainerInsertFct | Type for the insert_fct function parameter. |
str | The string to be split. |
delimiters | String with delimiter characters. Any of the characters in this string marks the beginning/end of a token. By default, a wide variety of whitespace and control characters is used. |
insert_fct | By default, tokenize() calls the emplace_back() member function on the container to insert strings. This parameter may contain a different function pointer or object with the signature void f(StringContainer&, std::string_view) that is called instead. This can be useful for containers that do not provide emplace_back() or for other customizations. |
char
s. This can have surprising effects in code such as this: References gul17::bit_set().
|
inline |
Split the given string into a vector of substrings (tokens) delimited by any of the characters in the delimiters string.
This function is identical to tokenize(std::string_view, std::string_view, ContainerInsertFct) except that it returns a std::vector of std::string_views instead of strings by default:
References gul17::bit_set().