#include <stdstring_tokenizer.h>
Public Member Functions | |
stdstring_tokenizer (const string &str, const string &separators) | |
Same as creating a stdstring_tokenizer and calling it's tokenize( str, separators ). | |
void | tokenize (const string &str, const string &separators) |
str is split up at points matching any element in separators. | |
string | next_token () |
Returns the next token in our list. | |
bool | has_tokens () const |
Returns true if this object has more tokens to give you. |
License: Public Domain Author: stephan@s11n.net
Based heavily off of work by:
Martin Jones (mjones@kde.org) Torben Weis (weis@kde.org) Waldo Bastian (bastian@kde.org)
which i originally found as string_tokenizer in the KDE 1.x source tree. i have received explicit permission from each of those gentlemen to release the string_tokenizer code into into the Public Domain. (Many thanks to them for that permission, without which this whole library would necessarily be released under the GNU GPL.)
This class is meant to be API- and behaviour-compatible with string_tokenizer. This implementation is, however, MUCH less efficient.
stdstring_tokenizer tokenizes strings in a way which is consistent with the way a Unix shell does. This makes it appropriate for use in parsing many types of arbitrary user input, from command-line arguments to comma-separated files.
Definition at line 41 of file stdstring_tokenizer.h.
|
Returns the next token in our list. Calling next_token() when has_tokens() returns false has undefined behaviour. |
|
str is split up at points matching any element in separators. Adjecent separators in str are interpreted as empty elements. Thus the string "1;;3", separated by ";", has 3 tokens: ("1","","3"). To collect the tokens, do this:
stdstring_tokenizer tok( "some string", " " ); while( tok.has_tokens() ) cout << "Token: " << tok.next_token() << endl; |