Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members

s11n::stdstring_tokenizer Class Reference

stdstring_tokenizer: More...

#include <stdstring_tokenizer.h>

List of all members.

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.


Detailed Description

stdstring_tokenizer:

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.


Member Function Documentation

string s11n::stdstring_tokenizer::next_token  ) 
 

Returns the next token in our list.

Calling next_token() when has_tokens() returns false has undefined behaviour.

void s11n::stdstring_tokenizer::tokenize const string &  str,
const string &  separators
 

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;


The documentation for this class was generated from the following file:
Generated on Tue Jul 20 10:46:49 2004 for s11n by doxygen 1.3.7