tokenizing a string made of "only" seperator characters
Hi All,
Following function utilizing boost's string tokenizer class crashes as might be expected:
Code:
bool CheckCommand(const string& cmd, const string& line)
{
if (line.length() == 0)
return false;
typedef tokenizer< char_separator<char> > StrTokenizer;
char_separator<char> sep(":");
StrTokenizer tokens(line, sep);
StrTokenizer::iterator it = tokens.begin();
if (*it == cmd) { <<<<--------------- Crash takes place at this line
++it;
if (it != tokens.end()) {
return true;
}
}
return false;
}
when line is "::::::::::::::::::::", i.e. made of merely separator characters (":").
How can I check
Code:
StrTokenizer::iterator it
actually points to something meaningful to prevent this crash ?
Thanks.
Re: tokenizing a string made of "only" seperator characters
Code:
if ( it != tokens.end() && *it == cmd )
bye!