incron
0.5.10
|
Simple string tokenizer class. More...
#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. |
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.
StringTokenizer::StringTokenizer | ( | const std::string & | rStr, |
char | cDelim = ',' , |
||
char | cPrefix = '\0' |
||
) |
Constructor.
Creates a ready-to-use tokenizer.
[in] | rStr | string for tokenizing |
[in] | cDelim | delimiter (separator) character |
[in] | cPrefix | character which is prepended if a character must not separate tokens |
StringTokenizer::~StringTokenizer | ( | ) | [inline] |
Destructor.
char StringTokenizer::GetDelimiter | ( | ) | const [inline] |
Returns the delimiter (separator) character.
std::string StringTokenizer::GetNextToken | ( | bool | fSkipEmpty = 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 '\').
[in] | fSkipEmpty | skip empty strings (more consecutive delimiters) |
std::string StringTokenizer::GetNextTokenRaw | ( | bool | fSkipEmpty = false | ) |
Returns the next token.
This method always returns an unmodified string even if it contains prefix characters.
[in] | fSkipEmpty | skip empty strings (more consecutive delimiters) |
char StringTokenizer::GetPrefix | ( | ) | const [inline] |
Returns the 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.
bool StringTokenizer::HasMoreTokens | ( | ) | const [inline] |
Checks whether the tokenizer can provide more tokens.
void StringTokenizer::Reset | ( | ) | [inline] |
Resets the tokenizer.
Re-initializes tokenizing to the start of the string.
void StringTokenizer::SetDelimiter | ( | char | cDelim | ) | [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.
[in] | cDelim | delimiter character |
void StringTokenizer::SetNoPrefix | ( | ) | [inline] |
Sets the prefix to 'no prefix'.
Calling this method is equivalent to SetPrefix((char) 0).
void StringTokenizer::SetPrefix | ( | char | cPrefix | ) | [inline] |
Sets a prefix character.
The new prefix has effect only to tokens returned later; the position in the string is not affected.
[in] | cPrefix | prefix character |