Пример #1
0
        public void SkipHeaderRows(IFileReader reader)
        {
            ArgumentVerifier.CheckObjectArgument(reader, "reader");

            if (this.headerRowsToSkip > 0 && !string.IsNullOrEmpty(this.headerRowDelimiter))
            {
                FieldParser headerRowFieldParser = FieldParser.BuildParserWithSingleDelimiter(this.headerRowDelimiter);

                for (int i = 0; i < this.headerRowsToSkip; i++)
                {
                    headerRowFieldParser.ParseNext(reader);
                    if (reader.IsEOF)
                    {
                        break;
                    }
                }
            }
        }
        public void ParseNextRow(IFileReader reader, RowData rowData)
        {
            ArgumentVerifier.CheckObjectArgument(reader, "reader");

            if (rowData != null)
            {
                rowData.ResetRowData();
            }
            this.fieldParser.ResetParsingState();

            if (this.singleColumn)
            {
                fieldParser.ParseNext(reader, rowData);
                if (rowData != null)
                {
                    string columnData = fieldParser.CurrentText;
                    if (!reader.IsEOF || !string.IsNullOrEmpty(columnData))
                    {
                        rowData.AddColumnData(fieldParser.CurrentText);
                    }
                }
            }
            else
            {
                while (!reader.IsEOF && !this.fieldParser.RowDelimiterMatch)
                {
                    this.fieldParser.ParseNext(reader, rowData);

                    if (rowData != null)
                    {
                        string columnData = fieldParser.CurrentText;
                        if (!reader.IsEOF || rowData.ColumnCount > 0 || !string.IsNullOrEmpty(columnData))
                        {
                            if (MaxColumnNumber == rowData.ColumnCount)
                            {
                                throw new RowColumnNumberOverflow();
                            }
                            // Add data if this is not the last and empty row.
                            rowData.AddColumnData(fieldParser.CurrentText);
                        }
                    }
                }
            }
        }
Пример #3
0
 static void VerifySuccessfulLastRowFieldParsing(FieldParser parser, IFileReader reader, string expectedText)
 {
     parser.ParseNext(reader);
     Assert.AreEqual<bool>(true, parser.RowDelimiterMatch);
     Assert.AreEqual<string>(expectedText, parser.CurrentText);
 }
Пример #4
0
 static void VerifySuccessfulFieldParsing(FieldParser parser, IFileReader reader, string expectedText)
 {
     parser.ParseNext(reader);
     Assert.AreEqual<string>(expectedText, parser.CurrentText);
 }