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

Add support for CSV escape character to EntityDataLoaderImpl #642

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class EntityDataLoaderImpl implements EntityDataLoader {
char csvDelimiter = ','
char csvCommentStart = '#'
char csvQuoteChar = '"'
char csvEscapeChar = '\\'

String csvEntityName = null
List<String> csvFieldNames = null
Expand Down Expand Up @@ -115,6 +116,7 @@ class EntityDataLoaderImpl implements EntityDataLoader {
@Override EntityDataLoader csvDelimiter(char delimiter) { this.csvDelimiter = delimiter; return this }
@Override EntityDataLoader csvCommentStart(char commentStart) { this.csvCommentStart = commentStart; return this }
@Override EntityDataLoader csvQuoteChar(char quoteChar) { this.csvQuoteChar = quoteChar; return this }
@Override EntityDataLoader csvEscapeChar(char escapeChar) { this.csvEscapeChar = escapeChar; return this }

@Override EntityDataLoader csvEntityName(String entityName) {
if (!efi.isEntityDefined(entityName) && !sfi.isServiceDefined(entityName))
Expand Down Expand Up @@ -925,6 +927,7 @@ class EntityDataLoaderImpl implements EntityDataLoader {
.withSkipHeaderRecord(true) // TODO: remove this? does it even do anything?
.withIgnoreEmptyLines(true)
.withIgnoreSurroundingSpaces(true)
.withEscape(edli.csvEscapeChar)
.parse(reader)

Iterator<CSVRecord> iterator = parser.iterator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public interface EntityDataLoader {
EntityDataLoader csvDelimiter(char delimiter);
EntityDataLoader csvCommentStart(char commentStart);
EntityDataLoader csvQuoteChar(char quoteChar);
EntityDataLoader csvEscapeChar(char escapeChar);

/** For CSV files use this name (entity or service name) instead of looking for it on line one in the file */
EntityDataLoader csvEntityName(String entityName);
Expand Down
Loading