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 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); }
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; }
public void MultiCharTokenWithNextAndErrorTest() { ParsingContextTestImpl context = new ParsingContextTestImpl(); ParsingStateTestImpl nextState = new ParsingStateTestImpl(ParsingResult.Match); ParsingStateTestImpl errorState = new ParsingStateTestImpl(ParsingResult.Match); MatchTokenParsingState target = new MatchTokenParsingState(":=>"); target.AddNextState(nextState); target.SetErrorState(errorState); Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'f'), ParsingResult.Miss); Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 't'), ParsingResult.Miss); Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, ':'), ParsingResult.Match); Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'x'), ParsingResult.Miss); Assert.AreEqual<IParsingState>(errorState, context.CurrentState); Assert.AreEqual<string>(":", context.CurrentText); context.ResetText(); 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<IParsingState>(nextState, context.CurrentState); Assert.AreEqual<string>(string.Empty, context.CurrentText); Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'y'), ParsingResult.Miss); Assert.AreEqual<ParsingResult>(target.ProcessCharacter(context, 'm'), 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<IParsingState>(nextState, context.CurrentState); Assert.AreEqual<string>(string.Empty, context.CurrentText); }
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; }