#include <evo/strtok.h>
String forward tokenizer.
- Variants: StrTokWord
- This skips whitespace (spaces, tabs) between delimiters so tokens will not start or end with any whitespace
- This references target string data – results are undefined if target string is modified while referenced
- For reverse tokenizing see: StrTokR
- For "strict" tokenizing (without skipping whitespace) see: StrTokS, StrTokRS
- Note: All tokenizers (including forward and reverse) implement the same basic interface (excluding
next*()
variants)
Example:
int main() {
while (tok.next(','))
return 0;
}
◆ BaseType
◆ Size
◆ ThisType
◆ StrTok() [1/4]
Default constructor creates empty tokenizer.
◆ StrTok() [2/4]
Copy constructor.
- Parameters
-
◆ StrTok() [3/4]
Copy constructor.
- Parameters
-
◆ StrTok() [4/4]
Constructor to start tokenizing given string.
- 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 using delimiter.
Call value() to get token value.
- This will skip leading whitespace (spaces, tabs) before and after next token
- Parameters
-
- Returns
- Whether next token was found, false if no more
◆ nextany()
Find next token using any of given delimiters.
Call value() to get token value.
- This will skip leading whitespace (spaces, tabs) before and after next token
- Parameters
-
- Returns
- Whether next token was found, false if no more
◆ nextanyq() [1/2]
bool nextanyq |
( |
const StringBase & |
delims, |
|
|
char |
ws_delim |
|
) |
| |
|
inline |
Find next token using any of given delimiters with quoting support.
Call value() to get token value.
- This will skip leading whitespace (spaces, tabs) before and after next token
- Token may be single-quoted ( ' ), double-quoted ( " ), backtick-quoted ( ` ), or triple-quoted ( ''' or """ or ``` )
- This also supports backtick-DEL quoting – backtick followed by the DEL char (7F) – used when no other quoting is possible
- Token is only considered quoted if it begins and ends with given quotes, after excluding whitespace – so an unquoted token can contain quote chars
- For best performance set
ws_delim
to 0 or the whitespace delimiter to skip whitespace delimiter detection
- Parameters
-
delims | Delimiters to use – must not have more than 1 whitespace character (space, tab, newline) |
ws_delim | Use to specify a whitespace char in delims so it's handled correctly, 1 to auto-detect, 0 if no whitespace delim |
- Returns
- Whether next token was found, false if no more
◆ nextanyq() [2/2]
Find next token using any of given delimiters with quoting support.
Call value() to get token value.
- This will skip leading whitespace (spaces, tabs) before and after next token
- Token may be single-quoted ( ' ), double-quoted ( " ), backtick-quoted ( ` ), or triple-quoted ( ''' or """ or ``` )
- This also supports backtick-DEL quoting – backtick followed by the DEL char (7F) – used when no other quoting is possible
- Token is only considered quoted if it begins and ends with given quotes, after excluding whitespace – so an unquoted token can contain quote chars
- For best performance use
nextanyq(const StringBase&,char)
and set ws_delim
to 0 or the whitespace delimiter to skip whitespace delimiter detection
- Parameters
-
delims | Delimiters to use – must not have more than 1 whitespace character (space, tab, newline) |
- Returns
- Whether next token was found, false if no more
◆ nextq()
Find next token using delimiter with quoting support.
Call value() to get token value.
- This will skip leading whitespace (spaces, tabs) before and after next token
- Token may be single-quoted ( ' ), double-quoted ( " ), backtick-quoted ( ` ), or triple-quoted ( ''' or """ or ``` )
- This also supports backtick-DEL quoting – backtick followed by the DEL char (7F) – used when no other quoting is possible
- Token is only considered quoted if it begins and ends with given quotes, after excluding whitespace – so an unquoted token can contain quote chars
- See Smart Quoting
- Parameters
-
- Returns
- Whether next token was found, false if no more
◆ nextw()
Find next token using word delimiter.
Call value() to get token value.
- Same as next(char) except this will also skip any leading extra delimiters before next token
- Parameters
-
- 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
◆ skipws()
Advance current position for next token by skipping whitespace.
- This gives the index where the next token starts
- This is useful for advanced parsing that needs to look at the context of next token (indent amount, characters before token, etc)
- Returns
- Current index for next token
◆ split()
static C::Size split |
( |
C & |
items, |
|
|
const T & |
str, |
|
|
char |
delim = ',' |
|
) |
| |
|
inlinestatic |
Split delimited string into item list using next().
- This tokenizes and adds each item 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 parameter |
T | String type to split – inferred from str parameter |
- Parameters
-
items | List to add items to [in/out] |
str | String to tokenize |
delim | Delimiter to use |
◆ splitat()
static SubString splitat |
( |
const T & |
str, |
|
|
Size |
index, |
|
|
char |
delim = ',' |
|
) |
| |
|
inlinestatic |
Split delimited string to extract token at index.
- This will tokenize until token at index is found
- Template Parameters
-
T | String type to tokenize – inferred from str parameter |
- Parameters
-
str | String to tokenize |
index | Token index to extract |
delim | Delimiter to use |
- 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: