private string ParseBlock(string blockName)
{
EatWhiteSpace();
StringBuilder blockText = new StringBuilder(DefaultBlockLength);
bool blockRead = false;
while (!blockRead && NextChar != EmptyChar)
{
string line = ReadLine();
string trimmedLine = line.TrimStart();
if (trimmedLine.Length >= VBKeyword.End.Length &&
trimmedLine.Substring(0, VBKeyword.End.Length).ToUpperInvariant() ==
VBKeyword.End.ToUpperInvariant())
{
if (trimmedLine.Length > VBKeyword.End.Length &&
IsWhiteSpace(trimmedLine[VBKeyword.End.Length]))
{
string restOfLine = trimmedLine.Substring(VBKeyword.End.Length).Trim();
if (restOfLine.ToUpperInvariant().StartsWith(blockName.ToUpperInvariant()) &&
(restOfLine.Length == blockName.Length ||
(restOfLine.Length > blockName.Length && IsWhiteSpace(restOfLine[blockName.Length]))))
{
blockRead = true;
}
else if (restOfLine.Length == 1 && restOfLine[0] == VBSymbol.LineContinuation)
{
string continuationLine = ReadLine();
if (continuationLine.Trim().ToUpperInvariant() == blockName.ToUpperInvariant())
{
blockRead = true;
}
else
{
blockText.AppendLine(line);
blockText.AppendLine(continuationLine);
line = string.Empty;
}
}
}
}
if (!blockRead)
{
blockText.AppendLine(line);
}
}
if (!blockRead)
{
this.OnParseError("Unexpected end of file. Expected End " + blockName);
}
return blockText.ToString().Trim();
}