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

#include <evo/strtok.h>

Inheritance diagram for StrTokLine:
Inheritance graph
[legend]

Detailed Description

String line tokenizer.

Example
#include <evo/strtok.h>
#include <evo/string.h>
#include <evo/io.h>
using namespace evo;
Console& c = con();
int main() {
String str = "one\ntwo\r\nthree";
StrTokLine tok(str);
while (tok.next())
c.out << tok.value() << NL;
return 0;
}

Output:

one
two
three

Public Types

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

Public Member Functions

 StrTokLine ()
 Default constructor creates empty tokenizer. More...
 
 StrTokLine (const ThisType &src)
 Copy constructor. More...
 
 StrTokLine (const BaseType &src)
 Copy constructor. More...
 
 StrTokLine (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 ()
 Find next token by finding next newline or newline pair. 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)
 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...
 

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

This type.

Constructor & Destructor Documentation

◆ StrTokLine() [1/4]

StrTokLine ( )
inline

Default constructor creates empty tokenizer.

◆ StrTokLine() [2/4]

StrTokLine ( const ThisType src)
inline

Copy constructor.

Parameters
srcData to copy

◆ StrTokLine() [3/4]

StrTokLine ( const BaseType src)
inline

Copy constructor.

Parameters
srcData to copy

◆ StrTokLine() [4/4]

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

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]

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 
)
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
CList container for items – inferred from items argument
TString type to split – inferred from str argument
Parameters
itemsList to add items to [in/out]
strString to tokenize

◆ splitat()

static SubString splitat ( const T &  str,
Size  index 
)
inlinestatic

Split string lines to extract token at line index.

  • This will tokenize until token at line index is found
Template Parameters
TString type to tokenize – inferred from str parameter
Parameters
strString to tokenize
indexToken line index to extract
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: