#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. |
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. Creates a ready-to-use tokenizer.
|
|
Destructor.
|
|
Returns the delimiter (separator) character.
|
|
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 '\').
|
|
Returns the next token. This method always returns an unmodified string even if it contains prefix characters.
|
|
Returns the prefix character.
|
|
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.
|
|
Checks whether the tokenizer can provide more tokens.
|
|
Resets the tokenizer. Re-initializes tokenizing to the start of the string. |
|
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.
|
|
Sets the prefix to 'no prefix'. Calling this method is equivalent to SetPrefix((char) 0).
|
|
Sets a prefix character. The new prefix has effect only to tokens returned later; the position in the string is not affected.
|