Esempio n. 1
0
        string ExtractQuote(ITextParser parser)
        {
            // Extract contents of quote
            parser.MoveAhead();
            var start = parser.Position;

            while (!parser.EndOfText && parser.Peek() != '"')
            {
                parser.MoveAhead();
            }
            return(parser.Extract(start, parser.Position));
        }
Esempio n. 2
0
        string ExtractBlock(
            ITextParser parser,
            char openChar,
            char closeChar)
        {
            // Track delimiter depth
            var depth = 1;

            // Extract characters between delimiters
            parser.MoveAhead();
            var start = parser.Position;

            while (!parser.EndOfText)
            {
                if (parser.Peek() == openChar)
                {
                    // Increase block depth
                    depth++;
                }
                else if (parser.Peek() == closeChar)
                {
                    // Decrease block depth
                    depth--;
                    // Test for end of block
                    if (depth == 0)
                    {
                        break;
                    }
                }
                else if (parser.Peek() == '"')
                {
                    // Don't count delimiters within quoted text
                    ExtractQuote(parser);
                }

                // Move to next character
                parser.MoveAhead();
            }

            return(parser.Extract(start, parser.Position));
        }