Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 46 → Rev 47

/incron/trunk/strtok.h
26,31 → 26,74
 
#include <string>
 
 
/// 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 the original string itself.
* The implementation is not ready to handle any changes of the
* string.
*
* The original string is left unchanged. All tokens are returned
* as newly created strings.
*/
class StringTokenizer
{
public:
/// Constructor.
/**
* Creates a ready-to-use tokenizer.
*
* \param[in] rStr string for tokenizing
* \param[in] cDelim delimiter (separator) character
*/
StringTokenizer(const std::string& rStr, char cDelim = ',');
/// Destructor.
~StringTokenizer() {}
/// Checks whether the tokenizer can provide more tokens.
/**
* \return true = more tokens available, false = otherwise
*/
inline bool HasMoreTokens() const
{
return m_pos < m_len;
}
/// Returns the next token.
/**
* \return next token or "" if no more tokens available
*/
std::string GetNextToken();
/// Sets a delimiter (separator) character.
/**
* The new delimiter has effect only to tokens returned later;
* the position in the string is not affected.
*
* \param[in] cDelim delimiter character
*/
inline void SetDelimiter(char cDelim)
{
m_cDelim = cDelim;
}
/// Returns the delimiter (separator) character.
/**
* \return delimiter character
*/
inline char GetDelimiter() const
{
return m_cDelim;
}
/// Resets the tokenizer.
/**
* Re-initializes tokenizing to the start of the string.
*/
inline void Reset()
{
m_pos = 0;
57,10 → 100,10
}
private:
std::string m_str;
char m_cDelim;
std::string::size_type m_pos;
std::string::size_type m_len;
std::string m_str; ///< tokenized string
char m_cDelim; ///< delimiter character
std::string::size_type m_pos; ///< current position
std::string::size_type m_len; ///< string length
};