Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

trim spaces: don't trim/strip separator character #100

Closed
Closed
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 @@ -925,7 +925,7 @@ protected final int _skipLeadingSpace() throws IOException
}
}
char ch = _inputBuffer[_inputPtr++];
if (ch > ' ') {
if (ch > ' ' || ch == _separatorChar) {
return ch;
}
switch (ch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,37 @@ public void testTrimming() throws Exception
assertFalse(it.hasNext());
it.close();
}

public void testTrimmingTabSeparated() throws Exception
{
CsvMapper mapper = mapperForCsv();
mapper.enable(CsvParser.Feature.TRIM_SPACES);
CsvSchema schema = mapper.schemaFor(Entry.class).withColumnSeparator('\t');
MappingIterator<Entry> it = mapper.readerFor(Entry.class).with(schema).
readValues(
"a\t\t c\n 1\t2\t\" 3\" \n\"ab\" \t\"c \t\"\t \n"
);
Entry entry;

assertTrue(it.hasNext());
assertNotNull(entry = it.nextValue());
assertEquals("a", entry.a);
assertEquals("", entry.b);
assertEquals("c", entry.c);

assertTrue(it.hasNext());
assertNotNull(entry = it.nextValue());
assertEquals("1", entry.a);
assertEquals("2", entry.b);
assertEquals(" 3", entry.c); // note: space within quotes is preserved

assertTrue(it.hasNext());
assertNotNull(entry = it.nextValue());
assertEquals("ab", entry.a);
assertEquals("c \t", entry.b);
assertEquals("", entry.c);

assertFalse(it.hasNext());
it.close();
}
}