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

Support escapes at beginning of the file #75

Merged
merged 1 commit into from
Apr 15, 2015
Merged
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 @@ -563,10 +563,17 @@ public String nextString() throws IOException
_textBuffer.resetWithString("");
return "";
}

char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
outBuf[0] = (char) i;
int outPtr = 1;

if (i == _escapeChar) {
// Reset the escaped character
outBuf[0] = _unescape();
return _nextUnquotedString(outBuf, outPtr);
}

int ptr = _inputPtr;
if (ptr >= _inputEnd) {
if (!loadMore()) { // ok to have end-of-input but...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,16 @@ public void testSimpleEscapesInUnquoted() throws Exception
assertEquals("abc\\def", result.id);
assertEquals("Desc with\nlinefeed", result.desc);
}


public void testEscapesAtStartInUnquoted() throws Exception
{
CsvMapper mapper = mapperForCsv();
CsvSchema schema = mapper.schemaFor(Desc.class).withColumnSeparator('|').withEscapeChar('\\');
final String id = "\\|abcdef"; // doubled for javac
final String desc = "Desc with\\\nlinefeed";
String input = id+"|"+desc+"\n";
Desc result = mapper.reader(schema).withType(Desc.class).readValue(input);
assertEquals("|abcdef", result.id);
assertEquals("Desc with\nlinefeed", result.desc);
}
}