You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2012/03/29 03:24:24 UTC

svn commit: r1306667 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVLexer.java test/java/org/apache/commons/csv/CSVLexerTest.java

Author: sebb
Date: Thu Mar 29 01:24:24 2012
New Revision: 1306667

URL: http://svn.apache.org/viewvc?rev=1306667&view=rev
Log:
Have to check for comment after dealing with empty lines.

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVLexer.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVLexer.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVLexer.java?rev=1306667&r1=1306666&r2=1306667&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVLexer.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVLexer.java Thu Mar 29 01:24:24 2012
@@ -46,12 +46,6 @@ class CSVLexer extends Lexer {
         //  read the next char and set eol
         int c = in.read();
 
-        if (isStartOfLine(lastChar) && isCommentStart(c)) {
-            in.readLine();
-            tkn.type = COMMENT;
-            return tkn;
-        }
-
         /* note: unfortunately isEndOfLine may consumes a character silently.
         *       this has no effect outside of the method. so a simple workaround
         *       is to call 'readAgain' on the stream...
@@ -83,6 +77,12 @@ class CSVLexer extends Lexer {
             return tkn;
         }
 
+        if (isStartOfLine(lastChar) && isCommentStart(c)) {
+            in.readLine();
+            tkn.type = COMMENT;
+            return tkn;
+        }
+
         //  important: make sure a new char gets consumed in each iteration
         while (tkn.type == INVALID) {
             // ignore whitespaces at beginning of a token

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java?rev=1306667&r1=1306666&r2=1306667&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVLexerTest.java Thu Mar 29 01:24:24 2012
@@ -58,11 +58,19 @@ public class CSVLexerTest {
     public void testNextToken2() throws IOException {
         final String code = 
                 "1,2,3,\n"+                // 1
+                "\n"+
+                "\n"+
                 "a,b x,c#no-comment\n"+    // 2
+                "\n"+
+                "\n"+
                 "#foo\n"+                  // 3
                 "\n"+                      // 4
                 "d,e,#no-comment\n"+       // 5
+                "\n"+
+                "\n"+
                 "# penultimate comment\n"+ // 6
+                "\n"+
+                "\n"+
                 "# Final comment\n";       // 7
         CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#');
         assertTrue("Should ignore empty lines", format.isEmptyLinesIgnored());