/** @file
$Id$
$Date$
$Author$
@copy © Marc Wäckerlin
@license LGPL, see file COPYING
$Log$
Revision 1.2 2004/12/20 07:40:36 marc
documentation improved, new grouping
Revision 1.1 2004/12/17 16:26:58 marc
initial version
*/
#include
#include
namespace mrw {
/** @addtogroup regexp
*/
//@{
/** @defgroup regexptokenizer Tokenizer
There is a Tokenizer which splits strings according to a list of
delimiters and allows to iterate over the individual tokens:
This code:
@code
mrw::Tokenizer token("first,second,third,,fifth", false, ",");
while (token) std::cout<<"TOKEN: '"<0 ? _pos+1 : _pos;
if (_pos==std::string::npos || _oldpos==std::string::npos) return false;
_pos = _text.find_first_of(_delim, _oldpos);
return true;
}
/** @brief access the token
Get the actual token. You must first call @c
Tokenizer::operator bool(), before you can access a
token. This method does not change the state of the object, so
it can be accessed several times and always returns the same
token.
@code
std::string actualToken = token();
@endcode
@return returns the actual token
@see @ref mrw::Tokenizer for an example
*/
std::string operator()() const throw(std::bad_exception) {
return _text.substr(_oldpos, _pos-_oldpos);
}
/** @brief reset the tokenizer
Resets the tokenizer so, that you can restart your iteration.
*/
void reset() throw() {
_pos = _oldpos = 0;
}
/** @brief reset the tokenizer and initializes it with a new text
Resets the tokenizer so, that you can restart your iteration
on new text.
@code
mrw::Tokenizer token("Hello World");
while (token) std::cout<<"-> "< "<