/// <summary>
/// Gets the type of code at offset.<br/>
/// 0 = Code,<br/>
/// 1 = Comment,<br/>
/// 2 = String<br/>
/// Block comments and multiline strings are not supported.
/// </summary>
static int GetStartType(TextDocument document, int linestart, int offset)
{
bool inString = false;
bool inChar = false;
bool verbatim = false;
int result = 0;
for (int i = linestart; i < offset; i++)
{
switch (document.GetCharAt(i))
{
case '/':
if (!inString && !inChar && i + 1 < document.TextLength)
{
if (document.GetCharAt(i + 1) == '/')
{
result = 1;
}
}
break;
case '"':
case '\'':
if (!inChar)
{
if (inString && verbatim)
{
if (i + 1 < document.TextLength && document.GetCharAt(i + 1) == '"')
{
++i; // skip escaped quote
inString = false; // let the string go on
}
else
{
verbatim = false;
}
}
else if (!inString && i > 0 && document.GetCharAt(i - 1) == '@')
{
verbatim = true;
}
inString = !inString;
}
break;
case '\\':
if ((inString && !verbatim) || inChar)
++i; // skip next character
break;
}
}
return (inString || inChar) ? 2 : result;
}