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 void MultiCharTokenWithEscapingTest()
 {
     ParsingContextTestImpl context = new ParsingContextTestImpl();
     MatchEscapedTokenParsingState target = new MatchEscapedTokenParsingState(":\":");
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'a'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'c'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'd'), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ','), ParsingResult.Miss);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, '\"'), ParsingResult.Match);
     Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Done);
 }
 public void EmptyTokenWithEscapingTest()
 {
     MatchEscapedTokenParsingState target = new MatchEscapedTokenParsingState(string.Empty);
 }
예제 #4
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;
        }