NArrange.VisualBasic.VBParser.ReadCodeLine C# (CSharp) Method

ReadCodeLine() private method

Reads a code line.
private ReadCodeLine ( ) : string
return string
        private string ReadCodeLine()
        {
            StringBuilder lineBuilder = new StringBuilder();
            char nextChar = NextChar;
            bool inString = false;
            while (!(nextChar == EmptyChar ||
                     nextChar == Environment.NewLine[0] ||
                     nextChar == '\n' ||
                     (!inString && nextChar == VBSymbol.LineDelimiter)))
            {
                TryReadChar();
                lineBuilder.Append(CurrentChar);
                if (CurrentChar == VBSymbol.BeginString)
                {
                    inString = !inString;
                }

                nextChar = NextChar;
                if (nextChar == VBSymbol.BeginComment && !inString)
                {
                    break;
                }
            }

            string line = lineBuilder.ToString();

            if (line != null && line.Trim().Length > 0)
            {
                string startTrimmedLine = line.TrimStart();
                string trimmedLine = startTrimmedLine.TrimEnd();

                bool isComment =
                    startTrimmedLine.StartsWith(VBSymbol.BeginComment.ToString(), StringComparison.OrdinalIgnoreCase) ||
                    (startTrimmedLine.StartsWith(VBKeyword.Rem, StringComparison.OrdinalIgnoreCase) &&
                     (startTrimmedLine.Length == trimmedLine.Length || startTrimmedLine[VBKeyword.Rem.Length] == ' '));

                if (!isComment &&
                    (trimmedLine == VBSymbol.LineContinuation.ToString() ||
                     (trimmedLine[trimmedLine.Length - 1] == VBSymbol.LineContinuation &&
                      IsWhiteSpace(trimmedLine[trimmedLine.Length - 2]))))
                {
                    ReadLine();
                    line = line.TrimEnd(VBSymbol.LineContinuation).TrimEnd(WhiteSpaceCharacters) + " " +
                           ReadCodeLine();
                }
            }

            return line;
        }