Skip to content

Commit

Permalink
fixes #15 back to SKIP_EMPTY_LINES
Browse files Browse the repository at this point in the history
  • Loading branch information
vboulaye authored and cowtowncoder committed Oct 8, 2019
1 parent 6afa34f commit 575ee59
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Expand Up @@ -78,8 +78,10 @@ public enum Feature
* depending on binding, `null`).
*<p>
* Feature is disabled by default.
*
* @since 2.10
*/
SKIP_BLANK_LINES(false),
SKIP_EMPTY_LINES(false),

/**
* Feature that allows there to be a trailing single extraneous data
Expand Down
Expand Up @@ -269,7 +269,7 @@ public CsvDecoder(IOContext ctxt, CsvParser owner, Reader r,
_textBuffer = textBuffer;
_autoCloseInput = StreamReadFeature.AUTO_CLOSE_SOURCE.enabledIn(stdFeatures);
_allowComments = CsvParser.Feature.ALLOW_COMMENTS.enabledIn(csvFeatures);
_skipBlankLines = CsvParser.Feature.SKIP_BLANK_LINES.enabledIn(csvFeatures);
_skipBlankLines = CsvParser.Feature.SKIP_EMPTY_LINES.enabledIn(csvFeatures);
_trimSpaces = CsvParser.Feature.TRIM_SPACES.enabledIn(csvFeatures);
_inputBuffer = ctxt.allocTokenBuffer();
_bufferRecyclable = true; // since we allocated it
Expand Down Expand Up @@ -478,6 +478,12 @@ public boolean startNewLine() throws IOException {
return skipLinesWhenNeeded();
}

/**
* optionally skip lines that are empty or are comments, depending on the feature activated in the parser
* @return false if the end of input was reached
* @throws IOException
* @since 2.10
*/
public boolean skipLinesWhenNeeded() throws IOException {
if (!(_allowComments || _skipBlankLines)) {
return hasMoreInput();
Expand Down
Expand Up @@ -27,7 +27,7 @@ public void testCsvWithEmptyLineSkipBlankLinesFeatureDisabled() throws Exception

public void testCsvWithEmptyLineSkipBlankLinesFeatureEnabled() throws Exception {
String[][] rows = mapperForCsvAsArray()
.with(CsvParser.Feature.SKIP_BLANK_LINES)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.readValue(CSV_WITH_EMPTY_LINE);
// empty line is skipped
assertArrayEquals(expected(
Expand All @@ -50,7 +50,7 @@ public void testCsvWithBlankLineSkipBlankLinesFeatureDisabled() throws Exception

public void testCsvWithBlankLineSkipBlankLinesFeatureEnabled() throws Exception {
String[][] rows = mapperForCsvAsArray()
.with(CsvParser.Feature.SKIP_BLANK_LINES)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.readValue(CSV_WITH_BLANK_LINE);
// blank line is skipped
assertArrayEquals(expected(
Expand All @@ -74,7 +74,7 @@ public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureDisabled() throws

public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws Exception {
String[][] rows = mapperForCsvAsArray()
.with(CsvParser.Feature.SKIP_BLANK_LINES)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.readValue(CSV_WITH_BLANK_LINE_AND_COMMENT);
// blank/empty lines are skipped
assertArrayEquals(expected(
Expand All @@ -86,7 +86,7 @@ public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabled() throws

public void testCsvWithBlankLineAndCommentSkipBlankLinesFeatureEnabledAndAllowComments() throws Exception {
String[][] rows = mapperForCsvAsArray()
.with(CsvParser.Feature.SKIP_BLANK_LINES)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.with(CsvParser.Feature.ALLOW_COMMENTS)
.readValue(CSV_WITH_BLANK_LINE_AND_COMMENT);
// blank/empty/comment lines are skipped
Expand All @@ -109,7 +109,7 @@ public void testCsvWithFirstBlankLineSkipBlankLinesFeatureDisabled() throws Exce

public void testCsvWithFirstBlankLineSkipBlankLinesFeatureEnabled() throws Exception {
String[][] rows = mapperForCsvAsArray()
.with(CsvParser.Feature.SKIP_BLANK_LINES)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.readValue(CSV_WITH_FIRST_BLANK_LINE);
// blank line is skipped
assertArrayEquals(expected(
Expand All @@ -133,7 +133,7 @@ public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureDisabled() throws E

public void testCsvWithTrailingBlankLineSkipBlankLinesFeatureEnabled() throws Exception {
String[][] rows = mapperForCsvAsArray()
.with(CsvParser.Feature.SKIP_BLANK_LINES)
.with(CsvParser.Feature.SKIP_EMPTY_LINES)
.readValue(CSV_WITH_FIRST_BLANK_LINE);
// blank lines are skipped
assertArrayEquals(expected(
Expand Down

0 comments on commit 575ee59

Please sign in to comment.