private string RemoveComments(string text)
{
if (_inMultiLineComment)
{
int commentEnd = text.IndexOf("*/");
if (commentEnd < 0)
{
return string.Empty;
}
text = text.Substring(commentEnd + 2);
_inMultiLineComment = false;
}
StringBuilder output = new StringBuilder(text.Length);
for (int i = 0; i < text.Length; i++)
{
if (!_inMultiLineComment)
{
if ((text[i] == '"') || (text[i] == '\''))
{
int endOfString = FindIndexOfMatchingCharacter(text, i, text[i]);
if (endOfString < 0)
{
break;
}
endOfString++;
output.Append(text.Substring(i, endOfString - i));
text = text.Substring(endOfString);
i = -1;
}
else if ((i < text.Length - 1) && (text[i] == '/') && (text[i + 1] == '/'))
{
break;
}
else if ((i < text.Length - 1) && (text[i] == '/') && (text[i + 1] == '*'))
{
_inMultiLineComment = true;
i++;
}
else
{
output.Append(text[i]);
}
}
else if ((i < text.Length - 1) && (text[i] == '*') && (text[i + 1] == '/'))
{
_inMultiLineComment = false;
i++;
}
}
return output.ToString().Trim();
}