3232 */
3333abstract class Lexer {
3434
35- private final Character delimiter ;
36- private final Character escape ;
37- private final Character encapsulator ;
38- private final Character commmentStart ;
35+ /**
36+ * Constant char to be used for disabling comments, escapes and encapsulation. The value -2 is used because it
37+ * won't be confused with an EOF signal (-1), and because the Unicode value {@code FFFE} would be encoded as two chars
38+ * (using surrogates) and thus there should never be a collision with a real text char.
39+ */
40+ private static final char DISABLED = '\ufffe' ;
41+
42+ private final char delimiter ;
43+ private final char escape ;
44+ private final char encapsulator ;
45+ private final char commmentStart ;
3946
4047 final boolean ignoreSurroundingSpaces ;
4148 final boolean ignoreEmptyLines ;
@@ -49,13 +56,17 @@ abstract class Lexer {
4956 this .format = format ;
5057 this .in = in ;
5158 this .delimiter = format .getDelimiter ();
52- this .escape = format .getEscape ();
53- this .encapsulator = format .getEncapsulator ();
54- this .commmentStart = format .getCommentStart ();
59+ this .escape = nullMeansDisabled ( format .getEscape () );
60+ this .encapsulator = nullMeansDisabled ( format .getEncapsulator () );
61+ this .commmentStart = nullMeansDisabled ( format .getCommentStart () );
5562 this .ignoreSurroundingSpaces = format .getIgnoreSurroundingSpaces ();
5663 this .ignoreEmptyLines = format .getIgnoreEmptyLines ();
5764 }
5865
66+ private final char nullMeansDisabled (Character c ) {
67+ return c == null ? DISABLED : c .charValue ();
68+ }
69+
5970 int getLineNumber () {
6071 return in .getLineNumber ();
6172 }
@@ -137,14 +148,14 @@ boolean isDelimiter(final int c) {
137148 }
138149
139150 boolean isEscape (final int c ) {
140- return escape != null && c == escape ;
151+ return c == escape ;
141152 }
142153
143154 boolean isEncapsulator (final int c ) {
144- return encapsulator != null && c == encapsulator ;
155+ return c == encapsulator ;
145156 }
146157
147158 boolean isCommentStart (final int c ) {
148- return commmentStart != null && c == commmentStart ;
159+ return c == commmentStart ;
149160 }
150161}
0 commit comments