Evo C++ Library v0.5.1
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
StrTokS Class Reference

#include <evo/strtok.h>

Inheritance diagram for StrTokS:
Inheritance graph
[legend]

Detailed Description

String forward tokenizer (strict).

Example:

#include <evo/strtok.h>
#include <evo/io.h>
using namespace evo;
int main() {
Console& c = con();
SubString str = "one,two,three";
// Tokens:
// one
// two
// three
StrTokS tok(str);
while (tok.next(','))
c.out << tok.value();
return 0;
}

Public Types

typedef StrTokBase BaseType
 Base type. More...
 
typedef SubString::Size Size
 String size type More...
 
typedef StrTokS ThisType
 This type. More...
 

Public Member Functions

 StrTokS ()
 Default constructor creates empty tokenizer. More...
 
 StrTokS (const ThisType &src)
 Copy constructor. More...
 
 StrTokS (const BaseType &src)
 Copy constructor. More...
 
 StrTokS (const StringBase &str)
 Constructor to start tokenizing given string. More...
 
Char delim () const
 Get current delimiter before next token. More...
 
Size index () const
 Get current index before next token. More...
 
bool next (char delim)
 Find next token using delimiter. More...
 
bool nextany (const StringBase &delims)
 Find next token using any of given delimiters. More...
 
bool nextw (char delim)
 Find next token using word delimiter. More...
 
ThisTypeoperator= (const ThisType &src)
 Assignment/Copy operator. More...
 
ThisTypeoperator= (const BaseType &src)
 Assignment/Copy operator. More...
 
ThisTypeoperator= (const StringBase &str)
 Assignment operator to start tokenizing given string from beginning. More...
 
ThisTypereset ()
 Reset to tokenize from beginning of string. More...
 
const SubStringvalue () const
 Get current token value from last call to next(). More...
 

Static Public Member Functions

template<class C , class T >
static C::Size split (C &items, const T &str, char delim=',')
 Split delimited string into item list using next(). More...
 
template<class T >
static SubString splitat (const T &str, Size index, char delim=',')
 Split delimited string to extract token at index. More...
 

Protected Member Functions

void copy (const BaseType &src)
 Copy data. More...
 

Protected Attributes

Char delim_
 Current delimiter, null when none or at end. More...
 
Size index_
 Current index, END when at end. More...
 
SubString string_
 String being tokenized, NULL for none More...
 
SubString value_
 Current value. More...
 

Member Typedef Documentation

◆ BaseType

Base type.

◆ Size

String size type

◆ ThisType

typedef StrTokS ThisType

This type.

Constructor & Destructor Documentation

◆ StrTokS() [1/4]

StrTokS ( )
inline

Default constructor creates empty tokenizer.

◆ StrTokS() [2/4]

StrTokS ( const ThisType src)
inline

Copy constructor.

Parameters
srcData to copy

◆ StrTokS() [3/4]

StrTokS ( const BaseType src)
inline

Copy constructor.

Parameters
srcData to copy

◆ StrTokS() [4/4]

StrTokS ( const StringBase str)
inline

Constructor to start tokenizing given string.

Call next() or nextw() for each token.

Parameters
strString to tokenize

Member Function Documentation

◆ copy()

void copy ( const BaseType src)
inlineprotectedinherited

Copy data.

◆ delim()

Char delim ( ) const
inlineinherited

Get current delimiter before next token.

Returns
Current delimiter, null if none or at end

◆ index()

Size index ( ) const
inlineinherited

Get current index before next token.

Returns
Current index, END if at end

◆ next()

bool next ( char  delim)
inline

Find next token using delimiter.

Call value() to get token value.

Parameters
delimDelimiter to use
Returns
Whether next token was found, false if no more

◆ nextany()

bool nextany ( const StringBase delims)
inline

Find next token using any of given delimiters.

Call value() to get token value.

Parameters
delimsDelimiters to use
Returns
Whether next token was found, false if no more

◆ nextw()

bool nextw ( char  delim)
inline

Find next token using word delimiter.

Call value() to get token value.

  • Same as next(char) except duplicate delimiters are skipped
Parameters
delimDelimiter to use
Returns
Whether next token was found, false if no more

◆ operator=() [1/3]

ThisType& operator= ( const ThisType src)
inline

Assignment/Copy operator.

Parameters
srcData to copy
Returns
This

◆ operator=() [2/3]

ThisType& operator= ( const BaseType src)
inline

Assignment/Copy operator.

Parameters
srcData to copy
Returns
This

◆ operator=() [3/3]

ThisType& operator= ( const StringBase str)
inline

Assignment operator to start tokenizing given string from beginning.

Call next() or nextw() for each token.

Parameters
strString to tokenize
Returns
This

◆ reset()

ThisType& reset ( )
inline

Reset to tokenize from beginning of string.

Returns
This

◆ 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
CList container for items – inferred from items parameter
TString type to split – inferred from str parameter
Parameters
itemsList to add items to [in/out]
strString to tokenize
delimDelimiter 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
TString type to tokenize – inferred from str parameter
Parameters
strString to tokenize
indexToken index to extract
delimDelimiter to use
Returns
Result token, set to null if not found

◆ value()

const SubString& value ( ) const
inlineinherited

Get current token value from last call to next().

Returns
Current token value

Member Data Documentation

◆ delim_

Char delim_
protectedinherited

Current delimiter, null when none or at end.

◆ index_

Size index_
protectedinherited

Current index, END when at end.

◆ string_

SubString string_
protectedinherited

String being tokenized, NULL for none

◆ value_

SubString value_
protectedinherited

Current value.


The documentation for this class was generated from the following file: