Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 626839687 for ; Tue, 27 Mar 2012 00:49:42 +0000 (UTC) Received: (qmail 28675 invoked by uid 500); 27 Mar 2012 00:49:41 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 28617 invoked by uid 500); 27 Mar 2012 00:49:41 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 28610 invoked by uid 99); 27 Mar 2012 00:49:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Mar 2012 00:49:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Mar 2012 00:49:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6979723889BB for ; Tue, 27 Mar 2012 00:49:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120327004918.6979723889BB@eris.apache.org> 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"));