#include <strutil.h>
Public Member Functions | |
Tokenizer (const std::string &str) | |
Tokenizer (const std::string &str, const std::string &delimiters) | |
bool | nextToken () |
bool | nextToken (const std::string &delimiters) |
const std::string | getToken () const |
void | reset () |
Static Public Attributes | |
static const std::string | DEFAULT_DELIMITERS |
Protected Attributes | |
size_t | m_Offset |
const std::string | m_String |
std::string | m_Token |
std::string | m_Delimiters |
String Tokenizer.
String tokenizer, which separate the whole string to tokens.
Definition at line 56 of file strutil.h.
strutil::Tokenizer::Tokenizer | ( | const std::string & | str | ) |
Definition at line 105 of file StrUtil.cpp.
: m_String(str), m_Offset(0), m_Delimiters(DEFAULT_DELIMITERS) {}
strutil::Tokenizer::Tokenizer | ( | const std::string & | str, | |
const std::string & | delimiters | |||
) |
Definition at line 108 of file StrUtil.cpp.
: m_String(str), m_Offset(0), m_Delimiters(delimiters) {}
const string strutil::Tokenizer::getToken | ( | ) | const |
Definition at line 137 of file StrUtil.cpp.
{ return m_Token; }
bool strutil::Tokenizer::nextToken | ( | const std::string & | delimiters | ) |
Definition at line 115 of file StrUtil.cpp.
{ // find the start charater of the next token. size_t i = m_String.find_first_not_of(delimiters, m_Offset); if (i == string::npos) { m_Offset = m_String.length(); return false; } // find the end of the token. size_t j = m_String.find_first_of(delimiters, i); if (j == string::npos) { m_Token = m_String.substr(i); m_Offset = m_String.length(); return true; } // to intercept the token and save current position m_Token = m_String.substr(i, j - i); m_Offset = j; return true; }
bool strutil::Tokenizer::nextToken | ( | ) |
Definition at line 111 of file StrUtil.cpp.
{ return nextToken(m_Delimiters); }
void strutil::Tokenizer::reset | ( | ) |
to reset the tokenizer. After reset it, the tokenizer can get the tokens from the first token.
Definition at line 141 of file StrUtil.cpp.
{ m_Offset = 0; }
const string strutil::Tokenizer::DEFAULT_DELIMITERS [static] |
std::string strutil::Tokenizer::m_Delimiters [protected] |
size_t strutil::Tokenizer::m_Offset [protected] |
const std::string strutil::Tokenizer::m_String [protected] |
std::string strutil::Tokenizer::m_Token [protected] |