public IInputGroup Parse(string input, IInputParserOptions inputParserOptions = null) { if (inputParserOptions == null) { inputParserOptions = Options; } bool withinQuotes = false; var currentWord = string.Empty; var parsedInputList = new List <string>(); for (var index = 1; index <= input.Length; index++) { var inputCharacter = input[index - 1]; if (inputParserOptions.InputQuoteGroups.Any(groupCharacter => groupCharacter == inputCharacter)) { withinQuotes = !withinQuotes; continue; } if (!withinQuotes && inputParserOptions.InputSeparatorGroups.Any(groupCharacter => groupCharacter == inputCharacter)) { parsedInputList.Add(currentWord); currentWord = string.Empty; continue; } currentWord += inputCharacter; } parsedInputList.Add(currentWord); return(new InputGroup(parsedInputList.ToArray())); }
public static IInputParserOptions Combine(this IInputParserOptions value, IInputParserOptions options) { var inputQuoteGroupList = value.InputQuoteGroups == null ? new List <char>() : value.InputQuoteGroups.ToList(); var inputSeparatorGroupList = value.InputSeparatorGroups == null ? new List <char>() : value.InputSeparatorGroups.ToList(); Action <IEnumerable <char>, IList <char> > Combine = (array, list) => { array.ForEach(optionQuoteGroupItem => { if (!list.Contains(optionQuoteGroupItem)) { list.Add(optionQuoteGroupItem); } }); }; Combine(options.InputQuoteGroups, inputQuoteGroupList); Combine(options.InputSeparatorGroups, inputSeparatorGroupList); return(new InputParserOptions { InputQuoteGroups = inputQuoteGroupList.ToArray(), InputSeparatorGroups = inputSeparatorGroupList.ToArray() }); }
public InputParser(IInputParserOptions inputParserOptions) { if (inputParserOptions == null) { inputParserOptions = InputParserOptions.Default; } this.Options = inputParserOptions; }