Lazy string splitter for getting tokens one by one.
More...
#include <utility.h>
|
| lazy_string_splitter (std::string_view text) |
| Takes a std::string_view object for reference while processing the text. More...
|
|
template<typename Callable > |
void | for_each (Callable &&cb) |
| If one needs to parse every single token, this is a good option as it will exhaust the splitter and keeps the code easy to read. More...
|
|
std::string_view | next () |
|
Lazy string splitter for getting tokens one by one.
A very small and limited splitter that parses tokens in between "." characters.
- Attention
- This method does not copy the text so it must remain available in the memory while this splitter operates on the text.
auto text = "a.b.c";
auto token = s.next();
token = s.next();
token = s.next();
◆ lazy_string_splitter()
garlic::lazy_string_splitter::lazy_string_splitter |
( |
std::string_view |
text | ) |
|
|
inline |
Takes a std::string_view object for reference while processing the text.
- Parameters
-
text | The text in which tokens are to be extracted. |
◆ for_each()
template<typename Callable >
void garlic::lazy_string_splitter::for_each |
( |
Callable && |
cb | ) |
|
|
inline |
If one needs to parse every single token, this is a good option as it will exhaust the splitter and keeps the code easy to read.
A helper method that takes a callback lambda and calls it with every parsed token.
- Parameters
-
cb | Any callable object that takes a std::string_view as its parameter. void (std::string_view) |
◆ next()
std::string_view garlic::lazy_string_splitter::next |
( |
| ) |
|
|
inline |
- Returns
- The next token or if exhausted, it will return an empty token.
- Note
- Empty token only gets returned when the splitter is exhausted.
The documentation for this class was generated from the following file: