Skip to content
Merged
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
43 changes: 23 additions & 20 deletions src/main/java/org/apache/commons/csv/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,7 @@ private Token parseEncapsulatedToken(final Token token) throws IOException {
}
}
} else if (isEscape(c)) {
if (isEscapeDelimiter()) {
token.content.append(delimiter);
} else {
final int unescaped = readEscape();
if (unescaped == EOF) { // unexpected char after escape
token.content.append((char) c).append((char) reader.getLastChar());
} else {
token.content.append((char) unescaped);
}
}
appendNextEscapedCharacterToToken(token);
} else if (isEndOfFile(c)) {
if (lenientEof) {
token.type = Token.Type.EOF;
Expand Down Expand Up @@ -412,16 +403,7 @@ private Token parseSimpleToken(final Token token, int ch) throws IOException {
}
// continue
if (isEscape(ch)) {
if (isEscapeDelimiter()) {
token.content.append(delimiter);
} else {
final int unescaped = readEscape();
if (unescaped == EOF) { // unexpected char after escape
token.content.append((char) ch).append((char) reader.getLastChar());
} else {
token.content.append((char) unescaped);
}
}
appendNextEscapedCharacterToToken(token);
} else {
token.content.append((char) ch);
}
Expand All @@ -435,6 +417,27 @@ private Token parseSimpleToken(final Token token, int ch) throws IOException {
return token;
}

/**
* Appends the next escaped character to the token's content.
*
* @param token
* the current token
* @throws IOException
* on stream access error
*/
private void appendNextEscapedCharacterToToken(final Token token) throws IOException {
if (isEscapeDelimiter()) {
token.content.append(delimiter);
} else {
final int unescaped = readEscape();
if (unescaped == EOF) { // unexpected char after escape
token.content.append(escape).append((char) reader.getLastChar());
} else {
token.content.append((char) unescaped);
}
}
}

/**
* Greedily accepts \n, \r and \r\n This checker consumes silently the second control-character...
*
Expand Down