CSV-75 ExtendedBufferReader does not handle EOL consistently
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1305694 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0833f45bff
commit
de1838ea06
|
@ -54,11 +54,11 @@ class ExtendedBufferedReader extends BufferedReader {
|
|||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
lastChar = super.read();
|
||||
|
||||
if (lastChar == '\n') {
|
||||
int current = super.read();
|
||||
if (current == '\r' || (current == '\n' && lastChar != '\r')) {
|
||||
lineCounter++;
|
||||
}
|
||||
lastChar = current;
|
||||
return lastChar;
|
||||
}
|
||||
|
||||
|
@ -85,14 +85,20 @@ class ExtendedBufferedReader extends BufferedReader {
|
|||
int len = super.read(buf, offset, length);
|
||||
|
||||
if (len > 0) {
|
||||
lastChar = buf[offset + len - 1];
|
||||
|
||||
|
||||
for (int i = offset; i < offset + len; i++) {
|
||||
if (buf[i] == '\n') {
|
||||
char ch = buf[i];
|
||||
if (ch == '\n') {
|
||||
if ('\r' != (i > 0 ? buf[i-1]: lastChar)) {
|
||||
lineCounter++;
|
||||
}
|
||||
} else if (ch == '\r') {
|
||||
lineCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lastChar = buf[offset + len - 1];
|
||||
|
||||
} else if (len == -1) {
|
||||
lastChar = END_OF_STREAM;
|
||||
}
|
||||
|
|
|
@ -502,7 +502,6 @@ public class CSVParserTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Line counting doesn't work with CR alone as the line separator, see CSV-75")
|
||||
public void testGetLineNumberWithCR() throws Exception {
|
||||
CSVParser parser = new CSVParser("a\rb\rc", CSVFormat.DEFAULT.withLineSeparator("\r"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue