I'm making a class for parsing HTML and one thing I need to make sure of is that I'm not parsing anything inside of either single or double quotation marks. What I've done is make an enumerator
enum quotation {OUTSIDE, INSIDE_SINGLE, INSIDE_DOUBLE};
inside the class and then use the following sort of pattern
void HtmlParser::toNextBracket()
{
/*
Adanvances _curIter to the pointer to the next angled bracket in
the range (_curIter, _offend]. If there is no angled bracket in
that range, then _curIter will equal _offend when the function
exits.
*/
while (_curIter != _offend)
{
++_curIter;
const char thisChar = getCurChar();
if (thisChar == '<' || thisChar == '>')
{
if (_quoteStatus == OUTSIDE) break;
}
else if (thisChar == '\'')
{
if (_quoteStatus == INSIDE_SINGLE) _quoteStatus = OUTSIDE;
else _quoteStatus = INSIDE_SINGLE;
}
else if (thisChar == '"')
{
if (_quoteStatus == INSIDE_DOUBLE) _quoteStatus = OUTSIDE;
else _quoteStatus = INSIDE_DOUBLE;
}
}
}
But I feel like there must be a better way of doing this. Which C++ tools should I be using for a more elegant procedure?