Example #1
0
        private Token NextToken(StringReader reader)
        {
            Skip(reader);

            string result = string.Empty;

            int c = reader.Peek();

            if (c == options.DelimiterCharacter)
            {
                reader.Read();

                return new Token(TokenType.Token);
            }
            else
            {
                if (IsQuoteCharacter(c))
                {
                    result = ReadQuoted(reader);

                    Skip(reader);

                    if (IsEndOfStream(reader.Peek()))
                    {
                        return new Token(TokenType.EndOfRecord, result);
                    }

                    if (IsDelimiter(reader.Peek()))
                    {
                        reader.Read();
                    }

                    return new Token(TokenType.Token, result);
                }

                if (IsEndOfStream(c))
                {
                    return new Token(TokenType.EndOfRecord);
                }
                else
                {
                    result = reader.ReadTo(options.DelimiterCharacter).Trim();

                    Skip(reader);

                    if (IsEndOfStream(reader.Peek()))
                    {
                        return new Token(TokenType.EndOfRecord, result);
                    }

                    if(IsDelimiter(reader.Peek()))
                    {
                        reader.Read();
                    }

                    return new Token(TokenType.Token, result);
                }
            }
        }
Example #2
0
        private string ReadQuoted(StringReader reader)
        {
            reader.Read();

            string result = reader.ReadTo(options.QuoteCharacter);

            reader.Read();

            if (reader.Peek() != options.QuoteCharacter)
            {
                return result;
            }

            StringBuilder buffer = new StringBuilder(result);
            do
            {
                buffer.Append((char)reader.Read());
                buffer.Append(reader.ReadTo(options.QuoteCharacter));

                reader.Read();
            } while (reader.Peek() == options.QuoteCharacter);

            return buffer.ToString();
        }