Esempio n. 1
0
        protected override int InnerParse(ParseArgs args)
        {
            var scanner = args.Scanner;
            var pos     = scanner.Position;

            if (quoteCharString != null)             // AllowQuoted
            {
                var ch = scanner.ReadChar();
                if (ch == -1)
                {
                    return(-1);
                }

                var quoteIndex = quoteCharString.IndexOf((char)ch);
                if (quoteIndex >= 0)
                {
                    var quote = (int)endQuoteCharString[quoteIndex];
beg:
                    ch = scanner.ReadChar();
                    if (ch != quote)
                    {
                        if (ch == -1)
                        {
                            goto end;
                        }

                        if (!AllowEscapeCharacters || ch != '\\')
                        {
                            goto beg;
                        }
                        // found escape character, read it
                        ch = scanner.ReadChar();
                        if (ch == -1)
                        {
                            goto end;
                        }
                        goto beg;
                    }

                    // reached quote, check for double quote
                    if (!AllowDoubleQuote || scanner.Peek() != quote)
                    {
                        return(scanner.Position - pos);
                    }

                    // double quote found, read it
                    scanner.ReadChar();
                    goto beg;
                }
end:
                scanner.Position = pos;
            }

            if (!AllowNonQuoted || NonQuotedLetter == null)
            {
                return(-1);
            }

            var length = 0;
            var m      = NonQuotedLetter.Parse(args);

            while (m > 0)
            {
                length += m;
                m       = NonQuotedLetter.Parse(args);
            }
            if (length > 0)
            {
                return(length);
            }

            return(-1);
        }
Esempio n. 2
0
        protected override int InnerParse(ParseArgs args)
        {
            int length  = 1;
            var scanner = args.Scanner;
            var pos     = scanner.Position;
            int ch;

            if (AllowQuoted)
            {
                ch = scanner.ReadChar();
                if (ch == -1)
                {
                    return(-1);
                }

                var quoteIndex = quoteCharString.IndexOf((char)ch);
                if (quoteIndex >= 0)
                {
                    char quote    = endQuoteCharString[quoteIndex];
                    bool isEscape = false;
                    ch = scanner.ReadChar();
                    while (ch != -1)
                    {
                        length++;
                        if (AllowEscapeCharacters && ch == '\\')
                        {
                            isEscape = true;
                        }
                        else if (!isEscape)
                        {
                            if (ch == quote)
                            {
                                if (!AllowDoubleQuote || scanner.Peek() != quote)
                                {
                                    return(length);
                                }
                                isEscape = true;
                            }
                        }
                        else
                        {
                            isEscape = false;
                        }

                        ch = scanner.ReadChar();
                    }
                }

                length           = 0;
                scanner.Position = pos;
            }

            if (AllowNonQuoted && NonQuotedLetter != null)
            {
                var m = NonQuotedLetter.Parse(args);
                while (m > 0)
                {
                    length += m;
                    m       = NonQuotedLetter.Parse(args);
                }
                if (length > 0)
                {
                    return(length);
                }
            }

            return(-1);
        }