public static FieldParser BuildParserWithSingleDelimiterAndQualifier(string delimiter, string qualifier)
        {
            ArgumentVerifier.CheckStringArgument(delimiter, "delimiter");
            ArgumentVerifier.CheckStringArgument(qualifier, "qualifier");

            FieldParser parser = new FieldParser();

            parser.initialParsingState = new ParsingState();
            ParsingState fieldState          = new ParsingState();
            ParsingState qualifiedFieldState = new ParsingState();

            MatchTokenParsingState        firstQualifierState  = new MatchTokenParsingState(qualifier);
            MatchTokenParsingState        delimiterState       = new MatchTokenParsingState(delimiter);
            MatchEscapedTokenParsingState secondQualifierState = new MatchEscapedTokenParsingState(qualifier);

            parser.initialParsingState.AddNextState(firstQualifierState);
            parser.initialParsingState.AddNextState(fieldState);

            fieldState.AddNextState(delimiterState);

            qualifiedFieldState.AddNextState(secondQualifierState);

            firstQualifierState.AddNextState(qualifiedFieldState);
            firstQualifierState.SetErrorState(fieldState);

            delimiterState.SetErrorState(fieldState);

            secondQualifierState.AddNextState(fieldState);
            secondQualifierState.SetErrorState(qualifiedFieldState);

            return(parser);
        }
        public RowParser(string columnDelimiter, string rowDelimiter, string qualifier)
        {
            ArgumentVerifier.CheckStringArgument(rowDelimiter, "rowDelimiter");

            if (string.IsNullOrEmpty(columnDelimiter))
            {
                this.singleColumn = true;
                if (string.IsNullOrEmpty(qualifier))
                {
                    this.fieldParser = FieldParser.BuildParserWithSingleDelimiter(rowDelimiter);
                }
                else
                {
                    this.fieldParser = FieldParser.BuildParserWithSingleDelimiterAndQualifier(rowDelimiter, qualifier);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(qualifier))
                {
                    this.fieldParser = FieldParser.BuildParserWithTwoDelimiters(columnDelimiter, rowDelimiter);
                }
                else
                {
                    this.fieldParser = FieldParser.BuildParserWithTwoDelimitersAndQualifier(columnDelimiter, rowDelimiter, qualifier);
                }
            }
        }
Пример #3
0
        public RowParser(string columnDelimiter, string rowDelimiter, string qualifier)
        {
            ArgumentVerifier.CheckStringArgument(rowDelimiter, "rowDelimiter");

            if (string.IsNullOrEmpty(columnDelimiter))
            {
                this.singleColumn = true;
                if (string.IsNullOrEmpty(qualifier))
                {
                    this.fieldParser = FieldParser.BuildParserWithSingleDelimiter(rowDelimiter);
                }
                else
                {
                    this.fieldParser = FieldParser.BuildParserWithSingleDelimiterAndQualifier(rowDelimiter, qualifier);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(qualifier))
                {
                    this.fieldParser = FieldParser.BuildParserWithTwoDelimiters(columnDelimiter, rowDelimiter);
                }
                else
                {
                    this.fieldParser = FieldParser.BuildParserWithTwoDelimitersAndQualifier(columnDelimiter, rowDelimiter, qualifier);
                }
            }
        }
        public static FieldParser BuildParserWithSingleDelimiter(string delimiter)
        {
            ArgumentVerifier.CheckStringArgument(delimiter, "delimiter");

            FieldParser parser = new FieldParser();

            parser.initialParsingState = new ParsingState();

            MatchTokenParsingState delimiterState = new MatchTokenParsingState(delimiter);

            parser.initialParsingState.AddNextState(delimiterState);

            delimiterState.SetErrorState(parser.initialParsingState);

            return(parser);
        }
Пример #5
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;
                    }
                }
            }
        }
Пример #6
0
        public static FieldParser BuildParserWithSingleDelimiter(string delimiter)
        {
            ArgumentVerifier.CheckStringArgument(delimiter, "delimiter");
            
            FieldParser parser = new FieldParser();
            
            parser.initialParsingState = new ParsingState();

            MatchTokenParsingState delimiterState = new MatchTokenParsingState(delimiter);

            parser.initialParsingState.AddNextState(delimiterState);

            delimiterState.SetErrorState(parser.initialParsingState);

            return parser;
        }
Пример #7
0
        public static FieldParser BuildParserWithTwoDelimitersAndQualifier(string delimiter, string rowDelimiter, string qualifier)
        {
            ArgumentVerifier.CheckStringArgument(delimiter, "delimiter");
            ArgumentVerifier.CheckStringArgument(rowDelimiter, "rowDelimiter");
            ArgumentVerifier.CheckStringArgument(qualifier, "qualifier");

            FieldParser parser = new FieldParser();

            parser.initialParsingState = new ParsingState();
            ParsingState fieldState = new ParsingState();
            ParsingState qualifiedFieldState = new ParsingState();

            MatchTokenParsingState firstQualifierState = new MatchTokenParsingState(qualifier);
            parser.rowDelimiterState = new MatchTokenParsingState(rowDelimiter);
            MatchTokenParsingState delimiterState = new MatchTokenParsingState(delimiter);
            MatchEscapedTokenParsingState secondQualifierState = new MatchEscapedTokenParsingState(qualifier);

            parser.initialParsingState.AddNextState(firstQualifierState);
            parser.initialParsingState.AddNextState(fieldState);

            fieldState.AddNextState(parser.rowDelimiterState);
            fieldState.AddNextState(delimiterState);

            qualifiedFieldState.AddNextState(secondQualifierState);

            firstQualifierState.AddNextState(qualifiedFieldState);
            firstQualifierState.SetErrorState(fieldState);

            parser.rowDelimiterState.SetErrorState(fieldState);

            delimiterState.SetErrorState(fieldState);

            secondQualifierState.AddNextState(fieldState);
            secondQualifierState.SetErrorState(qualifiedFieldState);

            return parser;
        }
Пример #8
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);
 }
Пример #9
0
 static void VerifySuccessfulFieldParsing(FieldParser parser, IFileReader reader, string expectedText)
 {
     parser.ParseNext(reader);
     Assert.AreEqual<string>(expectedText, parser.CurrentText);
 }