StringTokenizer(3)

NAME
StringTokenizer -

Simple string tokenizer class'.

SYNOPSIS

#include <strtok.h>

  Public Member Functions
StringTokenizer (const std::string &rStr, char cDelim= ',', char cPrefix= '\0')
Constructor'.
~StringTokenizer ()
Destructor'.
bool HasMoreTokens () const
Checks whether the tokenizer can provide more tokens'.
std::string GetNextToken (bool fSkipEmpty=false)
Returns the next token'.
std::string GetNextTokenRaw (bool fSkipEmpty=false)
Returns the next token'.
std::string GetRemainder ()
Returns the remainder of the source string'.
void SetDelimiter (char cDelim)
Sets a delimiter (separator) character'.
char GetDelimiter () const
Returns the delimiter (separator) character'.
void SetPrefix (char cPrefix)
Sets a prefix character'.
char GetPrefix () const
Returns the prefix character'.
void SetNoPrefix ()
Sets the prefix to 'no prefix''.
void Reset ()
Resets the tokenizer'.

Detailed Description

Simple string tokenizer class'. This class implements a string tokenizer'. It splits a string by a character to a number of elements (tokens) which are provided sequentially'.

All operations are made on a copy of the original string (which may be in fact a copy-on-write instance)'.

The original string is left unchanged'. All tokens are returned as newly created strings'.

There is possibility to specify a prefix character which causes the consecutive character is not considered as a delimiter'. If you don't specify this character (or specify the NUL character, 0x00) this feature is disabled'. The mostly used prefix is a backslash ('\')'.

This class is not thread-safe'.

Performance note: This class is currently not intended to be very fast'. Speed optimizations will be done later'.

Constructor & Destructor Documentation

  StringTokenizer::StringTokenizer (const std::string &rStr, charcDelim = ',', charcPrefix = '\0')

Constructor'. Creates a ready-to-use tokenizer'.

Parameters:
    rStr string for tokenizing
    cDelim delimiter (separator) character
    cPrefix character which is prepended if a character must not separate tokens

  StringTokenizer::~StringTokenizer () [inline]

Destructor'.

Member Function Documentation

  char StringTokenizer::GetDelimiter () const [inline]

Returns the delimiter (separator) character'. Returns:
    delimiter character

  std::string StringTokenizer::GetNextToken (boolfSkipEmpty = false)

Returns the next token'. If a prefix is defined it is stripped from the returned string (e'.g'. 'abc\ def' is transformed to 'abc def' while the prefix is '\')'.

Parameters:
    fSkipEmpty skip empty strings (more consecutive delimiters)

Returns:
    next token or '' if no more tokens available

See also:
    GetNextTokenRaw()

  std::string StringTokenizer::GetNextTokenRaw (boolfSkipEmpty = false)

Returns the next token'. This method always returns an unmodified string even if it contains prefix characters'.

Parameters:
    fSkipEmpty skip empty strings (more consecutive delimiters)

Returns:
    next token or '' if no more tokens available

See also:
    GetNextToken()

  char StringTokenizer::GetPrefix () const [inline]

Returns the prefix character'. Returns:
    prefix character

  std::string StringTokenizer::GetRemainder ()

Returns the remainder of the source string'. This method returns everything what has not been processed (tokenized) yet and moves the current position to the end of the string'.

If a prefix is defined it is stripped from the returned string'.

Returns:
    remainder string

  bool StringTokenizer::HasMoreTokens () const [inline]

Checks whether the tokenizer can provide more tokens'. Returns:
    true = more tokens available, false = otherwise

  void StringTokenizer::Reset () [inline]

Resets the tokenizer'. Re-initializes tokenizing to the start of the string'.

  void StringTokenizer::SetDelimiter (charcDelim) [inline]

Sets a delimiter (separator) character'. The new delimiter has effect only to tokens returned later; the position in the string is not affected'.

If you specify a NUL character (0x00) here the prefix will not be used'.

Parameters:
    cDelim delimiter character

  void StringTokenizer::SetNoPrefix () [inline]

Sets the prefix to 'no prefix''. Calling this method is equivalent to SetPrefix((char) 0)'.

See also:
    SetPrefix()

  void StringTokenizer::SetPrefix (charcPrefix) [inline]

Sets a prefix character'. The new prefix has effect only to tokens returned later; the position in the string is not affected'.

Parameters:
    cPrefix prefix character

See also:
    SetNoPrefix()

Author

Generated automatically by Doxygen for incron from the source code'.