Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 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));
     }
 }
Ejemplo n.º 4
0
 public TwoCharacterSeparatorMatcher(RetryReader reader, char first, char second)
 {
     this.reader = reader;
     this.first  = first;
     this.second = second;
 }
Ejemplo n.º 5
0
 public OneCharacterSeparatorMatcher(RetryReader reader, char first)
 {
     this.reader = reader;
     this.first  = first;
 }
Ejemplo n.º 6
0
 public DefaultSeparatorMatcher(RetryReader reader)
 {
     this.reader = reader;
 }
Ejemplo n.º 7
0
 public StringSeparatorMatcher(RetryReader reader, string separator)
 {
     this.reader    = reader;
     this.separator = separator;
 }
Ejemplo n.º 8
0
 public SeparatorRecordReader(TextReader reader, string separator)
 {
     this.reader  = new RetryReader(reader);
     this.matcher = SeparatorMatcher.GetMatcher(this.reader, separator);
     this.builder = new StringBuilder();
 }