#include <evo/strtok.h>
String line tokenizer.
- This references target string without allocating memory – results are undefined if target string is modified while referenced
- Tokens do not include the newline character(s), whitespace is left as-is
- Example
int main() {
String str =
"one\ntwo\r\nthree";
while (tok.next())
c.
out << tok.value() <<
NL;
return 0;
}
Output:
|
template<class C , class T > |
static C::Size | split (C &items, const T &str) |
| Split string lines into list using next(). More...
|
|
template<class T > |
static SubString | splitat (const T &str, Size index) |
| Split string lines to extract token at line index. More...
|
|
◆ BaseType
◆ Size
◆ ThisType
◆ StrTokLine() [1/4]
Default constructor creates empty tokenizer.
◆ StrTokLine() [2/4]
Copy constructor.
- Parameters
-
◆ StrTokLine() [3/4]
Copy constructor.
- Parameters
-
◆ StrTokLine() [4/4]
Constructor to start tokenizing given string.
- Call next() or nextw() for each token
- Parameters
-
◆ copy()
◆ delim()
Get current delimiter before next token.
- Returns
- Current delimiter, null if none or at end
◆ index()
Get current index before next token.
- Returns
- Current index, END if at end
◆ next()
Find next token by finding next newline or newline pair.
- Call value() to get token value
- This recognizes all the main newlines types, see Newline
- Note that this does NOT populate delim() – it will always be null
- Returns
- Whether next token was found, false if no more
◆ operator=() [1/3]
Assignment/Copy operator.
- Parameters
-
- Returns
- This
◆ operator=() [2/3]
Assignment/Copy operator.
- Parameters
-
- Returns
- This
◆ operator=() [3/3]
Assignment operator to start tokenizing given string from beginning.
Call next() or nextw() for each token.
- Parameters
-
- Returns
- This
◆ reset()
Reset to tokenize from beginning of string.
- Returns
- This
◆ split()
static C::Size split |
( |
C & |
items, |
|
|
const T & |
str |
|
) |
| |
|
inlinestatic |
Split string lines into list using next().
- This tokenizes and adds each line to list, using convert() for conversion to list item type
- String must be convertible to list item type via convert()
- See String::join() to join list back into string
- Template Parameters
-
C | List container for items – inferred from items argument |
T | String type to split – inferred from str argument |
- Parameters
-
items | List to add items to [in/out] |
str | String to tokenize |
◆ splitat()
Split string lines to extract token at line index.
- This will tokenize until token at line index is found
- Template Parameters
-
T | String type to tokenize – inferred from str parameter |
- Parameters
-
str | String to tokenize |
index | Token line index to extract |
- Returns
- Result token, set to null if not found
◆ value()
Get current token value from last call to next().
- Returns
- Current token value
◆ delim_
Current delimiter, null when none or at end.
◆ index_
Current index, END when at end.
◆ string_
String being tokenized, NULL for none
◆ value_
The documentation for this class was generated from the following file: