public bool InsideStringOrComment(bool charJustAdded, int position)
{
Cpp style = (Cpp)this.scintillaControl1.GetStyleAt(position - (charJustAdded ? 2 : 1));
if ((style == Cpp.CommentLine) || (style == Cpp.Comment) ||
(style == Cpp.CommentDoc) || (style == Cpp.CommentLineDoc) ||
(style == Cpp.String))
{
return true;
}
int lineNumber = this.scintillaControl1.LineFromPosition(position);
int lineStart = this.scintillaControl1.PositionFromLine(lineNumber);
string curLine = this.scintillaControl1.GetLine(lineNumber);
if (curLine.Length > 0)
{
int length = position - lineStart;
if (length >= curLine.Length)
{
length = curLine.Length - 1;
}
curLine = curLine.Substring(0, length);
}
if (curLine.IndexOf('"') >= 0)
{
int curIndex = 0;
int numSpeechMarks = 0;
while ((curIndex = curLine.IndexOf('"', curIndex)) >= 0)
{
numSpeechMarks++;
curIndex++;
}
if (numSpeechMarks % 2 == 1)
{
// in a string literal
return true;
}
}
return false;
}