commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r558883 - /jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVParser.java
Date Mon, 23 Jul 2007 22:25:15 GMT
Author: mbenson
Date: Mon Jul 23 15:25:10 2007
New Revision: 558883

URL: http://svn.apache.org/viewvc?view=rev&rev=558883
Log:
fix eol detection

Modified:
    jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVParser.java

Modified: jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVParser.java
URL: http://svn.apache.org/viewvc/jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVParser.java?view=diff&rev=558883&r1=558882&r2=558883
==============================================================================
--- jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVParser.java (original)
+++ jakarta/commons/sandbox/csv/trunk/src/java/org/apache/commons/csv/CSVParser.java Mon Jul
23 15:25:10 2007
@@ -459,6 +459,7 @@
     // assert c == delimiter;
     c = in.read();
     while (!tkn.isReady) {
+      boolean skipRead = false;
       if (c == strategy.getEncapsulator() || c == '\\') {
         // check lookahead
         if (in.lookAhead() == strategy.getEncapsulator()) {
@@ -483,26 +484,26 @@
         } else {
           // token finish mark (encapsulator) reached: ignore whitespace till delimiter
           while (!tkn.isReady) {
-            int n = in.lookAhead();
-            if (n == strategy.getDelimiter()) {
+            c = in.read();
+            if (c == strategy.getDelimiter()) {
               tkn.type = TT_TOKEN;
               tkn.isReady = true;
-            } else if (isEndOfFile(n)) {
+            } else if (isEndOfFile(c)) {
               tkn.type = TT_EOF;
               tkn.isReady = true;
-            } else if (isEndOfLine(n)) {
+            } else if (isEndOfLine(c)) {
               // ok eo token reached
               tkn.type = TT_EORECORD;
               tkn.isReady = true;
-            } else if (!isWhitespace(n)) {
-              // error invalid char between token and next delimiter
-              throw new IOException(
-                "(line " + getLineNumber() 
-                + ") invalid char between encapsualted token end delimiter"
-              );
-            }
-            c = in.read();
+            } else if (!isWhitespace(c)) {
+                // error invalid char between token and next delimiter
+                throw new IOException(
+                  "(line " + getLineNumber() 
+                  + ") invalid char between encapsulated token end delimiter"
+                );
+              }
           }
+          skipRead = true;
         }
       } else if (isEndOfFile(c)) {
         // error condition (end of file before end of token)
@@ -515,8 +516,8 @@
         tkn.content.append((char) c);
       }
       // get the next char
-      if (!tkn.isReady) {
-        c = in.read();  
+      if (!tkn.isReady && !skipRead) {
+        c = in.read();
       }
     }
     return tkn;



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message