garlic::lazy_string_splitter Class Reference

Lazy string splitter for getting tokens one by one. More...

#include <utility.h>

Public Member Functions

 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 ()
 

Detailed Description

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(); // a
token = s.next(); // b
token = s.next(); // c

Constructor & Destructor Documentation

◆ 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
textThe text in which tokens are to be extracted.

Member Function Documentation

◆ 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
cbAny callable object that takes a std::string_view as its parameter. void (std::string_view)
lazy_string_splitter("a.b.c").for_each([](std::string_view token){ std::cout << token; });

◆ 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:
garlic::lazy_string_splitter::lazy_string_splitter
lazy_string_splitter(std::string_view text)
Takes a std::string_view object for reference while processing the text.
Definition: utility.h:89