private string ParseNestedText(char beginChar, char endChar, bool beginExpected, bool trim)
{
StringBuilder blockText = new StringBuilder(DefaultBlockLength);
if (beginChar != EmptyChar && beginExpected)
{
while (IsWhiteSpace(NextChar))
{
TryReadChar();
if (!trim)
{
blockText.Append(CurrentChar);
}
}
EatChar(beginChar);
}
int depth = 1;
char nextChar = NextChar;
if (nextChar == EmptyChar)
{
this.OnParseError("Unexpected end of file. Expected " + endChar);
}
else if (nextChar == endChar)
{
TryReadChar();
}
else
{
bool inString = false;
while (depth > 0)
{
bool charRead = TryReadChar();
if (!charRead)
{
this.OnParseError("Unexpected end of file. Expected " + endChar);
}
nextChar = NextChar;
if (CurrentChar == VBSymbol.BeginString)
{
inString = !inString;
}
if (beginChar != EmptyChar && CurrentChar == beginChar &&
!inString)
{
blockText.Append(CurrentChar);
depth++;
}
else
{
blockText.Append(CurrentChar);
}
if (nextChar == endChar && !inString)
{
if (depth == 1)
{
EatChar(endChar);
break;
}
else
{
depth--;
}
}
}
}
if (trim)
{
return blockText.ToString().Trim();
}
else
{
return blockText.ToString();
}
}