commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1305694 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/ExtendedBufferedReader.java test/java/org/apache/commons/csv/CSVParserTest.java
Date Tue, 27 Mar 2012 00:49:18 GMT
Author: sebb
Date: Tue Mar 27 00:49:17 2012
New Revision: 1305694

URL: http://svn.apache.org/viewvc?rev=1305694&view=rev
Log:
CSV-75 ExtendedBufferReader does not handle EOL consistently

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java?rev=1305694&r1=1305693&r2=1305694&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
(original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Tue Mar 27 00:49:17 2012
@@ -54,11 +54,11 @@ class ExtendedBufferedReader extends Buf
 
     @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 Buf
         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;
         }

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1305694&r1=1305693&r2=1305694&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Tue Mar
27 00:49:17 2012
@@ -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"));
         



Mime
View raw message