static IEnumerable <KeyValuePair <char, int> > GetTextWithoutCommentsAndStrings(Mono.TextEditor.TextDocument doc, int start, int end)
{
bool isInString = false, isInChar = false;
bool isInLineComment = false, isInBlockComment = false;
for (int pos = start; pos < end; pos++)
{
char ch = doc.GetCharAt(pos);
switch (ch)
{
case '\r':
case '\n':
isInLineComment = false;
break;
case '/':
if (isInBlockComment)
{
if (pos > 0 && doc.GetCharAt(pos - 1) == '*')
{
isInBlockComment = false;
}
}
else if (!isInString && !isInChar && pos + 1 < doc.TextLength)
{
char nextChar = doc.GetCharAt(pos + 1);
if (nextChar == '/')
{
isInLineComment = true;
}
if (!isInLineComment && nextChar == '*')
{
isInBlockComment = true;
}
}
break;
case '"':
if (!(isInChar || isInLineComment || isInBlockComment))
{
isInString = !isInString;
}
break;
case '\'':
if (!(isInString || isInLineComment || isInBlockComment))
{
isInChar = !isInChar;
}
break;
default:
if (!(isInString || isInChar || isInLineComment || isInBlockComment))
{
yield return(new KeyValuePair <char, int> (ch, pos));
}
break;
}
}
}