commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1397863 - /commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java
Date Sat, 13 Oct 2012 15:41:56 GMT
Author: ggregory
Date: Sat Oct 13 15:41:56 2012
New Revision: 1397863

URL: http://svn.apache.org/viewvc?rev=1397863&view=rev
Log:
[CSV-94] Lexer should only use char fields.

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java?rev=1397863&r1=1397862&r2=1397863&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/Lexer.java Sat Oct 13 15:41:56
2012
@@ -32,10 +32,17 @@ import java.io.IOException;
  */
 abstract class Lexer {
 
-    private final Character delimiter;
-    private final Character escape;
-    private final Character encapsulator;
-    private final Character commmentStart;
+    /**
+     * Constant char to be used for disabling comments, escapes and encapsulation. The value
-2 is used because it
+     * won't be confused with an EOF signal (-1), and because the Unicode value {@code FFFE}
would be encoded as two chars
+     * (using surrogates) and thus there should never be a collision with a real text char.
+     */
+    private static final char DISABLED = '\ufffe';
+
+    private final char delimiter;
+    private final char escape;
+    private final char encapsulator;
+    private final char commmentStart;
 
     final boolean ignoreSurroundingSpaces;
     final boolean ignoreEmptyLines;
@@ -49,13 +56,17 @@ abstract class Lexer {
         this.format = format;
         this.in = in;
         this.delimiter = format.getDelimiter();
-        this.escape = format.getEscape();
-        this.encapsulator = format.getEncapsulator();
-        this.commmentStart = format.getCommentStart();
+        this.escape = nullMeansDisabled(format.getEscape());
+        this.encapsulator = nullMeansDisabled(format.getEncapsulator());
+        this.commmentStart = nullMeansDisabled(format.getCommentStart());
         this.ignoreSurroundingSpaces = format.getIgnoreSurroundingSpaces();
         this.ignoreEmptyLines = format.getIgnoreEmptyLines();
     }
 
+    private final char nullMeansDisabled(Character c) {
+        return c == null ? DISABLED : c.charValue();
+    }
+
     int getLineNumber() {
         return in.getLineNumber();
     }
@@ -137,14 +148,14 @@ abstract class Lexer {
     }
 
     boolean isEscape(final int c) {
-        return escape != null && c == escape;
+        return c == escape;
     }
 
     boolean isEncapsulator(final int c) {
-        return encapsulator != null && c == encapsulator;
+        return c == encapsulator;
     }
 
     boolean isCommentStart(final int c) {
-        return commmentStart != null && c == commmentStart;
+        return c == commmentStart;
     }
 }



Mime
View raw message