private SeparatedValueReader(TextReader reader, SeparatedValueSchema schema, SeparatedValueOptions options, bool hasSchema) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (hasSchema && schema == null) { throw new ArgumentNullException(nameof(schema)); } if (options == null) { options = new SeparatedValueOptions(); } if (options.RecordSeparator == options.Separator) { throw new ArgumentException(SharedResources.SameSeparator, nameof(options)); } RetryReader retryReader = new RetryReader(reader); this.parser = new SeparatedValueRecordParser(retryReader, options); if (hasSchema) { this.schema = schema; } }
public SeparatedValueRecordParser(RetryReader reader, SeparatedValueOptions options) { this.reader = reader; this.options = options.Clone(); this.separatorMatcher = SeparatorMatcher.GetMatcher(reader, options.Separator); this.recordSeparatorMatcher = SeparatorMatcher.GetMatcher(reader, options.RecordSeparator); if (options.RecordSeparator != null && options.RecordSeparator.StartsWith(options.Separator)) { string postfix = options.RecordSeparator.Substring(options.Separator.Length); this.postfixMatcher = SeparatorMatcher.GetMatcher(reader, postfix); } this.separatorLength = Math.Max(this.options.RecordSeparator?.Length ?? 2, this.options.Separator.Length); this.tokens = new List <string>(); this.token = new StringBuilder(); }
public static ISeparatorMatcher GetMatcher(RetryReader reader, string separator) { if (separator == null) { return(new DefaultSeparatorMatcher(reader)); } else if (separator.Length == 1) { return(new OneCharacterSeparatorMatcher(reader, separator[0])); } else if (separator.Length == 2) { return(new TwoCharacterSeparatorMatcher(reader, separator[0], separator[1])); } else { return(new StringSeparatorMatcher(reader, separator)); } }
public TwoCharacterSeparatorMatcher(RetryReader reader, char first, char second) { this.reader = reader; this.first = first; this.second = second; }
public OneCharacterSeparatorMatcher(RetryReader reader, char first) { this.reader = reader; this.first = first; }
public DefaultSeparatorMatcher(RetryReader reader) { this.reader = reader; }
public StringSeparatorMatcher(RetryReader reader, string separator) { this.reader = reader; this.separator = separator; }
public SeparatorRecordReader(TextReader reader, string separator) { this.reader = new RetryReader(reader); this.matcher = SeparatorMatcher.GetMatcher(this.reader, separator); this.builder = new StringBuilder(); }