#include <strtool.hpp>
Public Member Functions | |
stdstring_tokenizer () | |
stdstring_tokenizer (const std::string &str, const std::string &separators) | |
Same as creating a stdstring_tokenizer and calling it's tokenize( str, separators ). | |
~stdstring_tokenizer () | |
void | tokenize (const std::string &str, const std::string &separators) |
str is split up at points matching any element in separators. | |
std::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) and 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!)
This class is meant to be API- and behaviour-compatible with string_tokenizer. This implementation is, however, MUCH less efficient, and works on std::strings instead of C-style strings (const char *).
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 524 of file strtool.hpp.
s11n::io::strtool::stdstring_tokenizer::stdstring_tokenizer | ( | ) |
s11n::io::strtool::stdstring_tokenizer::stdstring_tokenizer | ( | const std::string & | str, | |
const std::string & | separators | |||
) |
Same as creating a stdstring_tokenizer and calling it's tokenize( str, separators ).
s11n::io::strtool::stdstring_tokenizer::~stdstring_tokenizer | ( | ) |
void s11n::io::strtool::stdstring_tokenizer::tokenize | ( | const std::string & | str, | |
const std::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;
std::string s11n::io::strtool::stdstring_tokenizer::next_token | ( | ) |
Returns the next token in our list.
Calling next_token() when has_tokens() returns false has undefined behaviour.
bool s11n::io::strtool::stdstring_tokenizer::has_tokens | ( | ) | const |
Returns true if this object has more tokens to give you.