public CSVParser(char separator = DEFAULT_SEPARATOR, char quotechar = DEFAULT_QUOTE_CHARACTER, char escape = DEFAULT_ESCAPE_CHARACTER, bool strictQuotes = DEFAULT_STRICT_QUOTES, bool ignoreLeadingWhiteSpace = DEFAULT_IGNORE_LEADING_WHITESPACE, bool ignoreQuotations = DEFAULT_IGNORE_QUOTATIONS, CSVReaderNullFieldIndicator nullFieldIndicator = DEFAULT_NULL_FIELD_INDICATOR) { if (AnyCharactersAreTheSame(separator, quotechar, escape)) { throw new NotSupportedException("The separator, quote, and escape characters must be different!"); } if (separator == NULL_CHARACTER) { throw new NotSupportedException("The separator character must be defined!"); } this.separator = separator; this.quotechar = quotechar; this.escape = escape; this.strictQuotes = strictQuotes; this.ignoreLeadingWhiteSpace = ignoreLeadingWhiteSpace; this.ignoreQuotations = ignoreQuotations; this.nullFieldIndicator = nullFieldIndicator; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleCSV.CSVParser"/> class with supplied separator, quote char and escape char. /// Allows setting the "strict quotes", "ignore leadig whitespace", "ignore quotations" flags and null field indicator. /// </summary> /// <param name="separator">The delimiter to use for separating entries.</param> /// <param name="quoteChar">The character to use for quoted elements.</param> /// <param name="escapeChar">The character to use for escaping a separator or quote.</param> /// <param name="strictQuotes">If <c>true</c>, characters outside the quotes are ignored.</param> /// <param name="ignoreLeadingWhiteSpace">If <c>true</c>, white space in front of a quote in a field is ignored.</param> /// <param name="ignoreQuotations">If set to <c>true</c>, treat quotations like any other character.</param> /// <param name="nullFieldIndicator">which field content will be returned as null: /// <c>EmptySeparators</c>, <c>EmptyQuotes</c>, <c>Both</c>, <c>Neither</c> (default).</param> public CSVParser(char separator, char quoteChar, char escapeChar, bool strictQuotes, bool ignoreLeadingWhiteSpace, bool ignoreQuotations, CSVReaderNullFieldIndicator nullFieldIndicator) { if (AnyCharactersAreTheSame(separator, quoteChar, escapeChar)) { throw new ArgumentException("The separator, quote, and escape characters must be different!"); } if (separator == NullCharacter) { throw new ArgumentException("The separator character must be defined!"); } Separator = separator; QuoteChar = quoteChar; EscapeChar = escapeChar; IsStrictQuotes = strictQuotes; IsIgnoreLeadingWhiteSpace = ignoreLeadingWhiteSpace; IsIgnoreQuotations = ignoreQuotations; NullFieldIndicator = nullFieldIndicator; LinesRead = 0; }
/// <summary> /// Checks to see if it should treat an field with two separators, two quotes, or both as a null field. /// </summary> /// <returns>The CSVReaderBuilder based on this criteria.</returns> /// <param name="indicator">CSVReaderNullFieldIndicator set to what should be considered a null field.</param> public CSVReaderBuilder WithFieldAsNull(CSVReaderNullFieldIndicator indicator) { this.nullFieldIndicator = indicator; return(this); }