Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the option to make header parsing case-sensitive. #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions code/LumenWorks.Framework.IO/Csv/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,9 +1418,12 @@ public bool ReadNextRecord()
/// Indicates if the reader will skip directly to the next line without parsing the current one.
/// To be used when an error occurs.
/// </param>
/// <param name="caseSensitiveHeaders">
/// Indicates if the reader should be case-sensitive when parsing headers.
/// </param>
/// <returns><see langword="true"/> if a record has been successfully reads; otherwise, <see langword="false"/>.</returns>
/// <exception cref="T:System.ComponentModel.ObjectDisposedException">The instance has been disposed of.</exception>
protected virtual bool ReadNextRecord(bool onlyReadHeaders, bool skipToNextLine)
protected virtual bool ReadNextRecord(bool onlyReadHeaders, bool skipToNextLine, bool caseSensitiveHeaders = false)
{
if (_eof)
{
Expand Down Expand Up @@ -1488,7 +1491,8 @@ protected virtual bool ReadNextRecord(bool onlyReadHeaders, bool skipToNextLine)
Array.Resize(ref _fields, _fieldCount);
}

_fieldHeaderIndexes = new Dictionary<string, int>(_fieldCount, StringComparer.CurrentCultureIgnoreCase);
var headerComparer = caseSensitiveHeaders ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase;
_fieldHeaderIndexes = new Dictionary<string, int>(_fieldCount, headerComparer);

_initialized = true;

Expand Down