Skip to content

Commit 1ae3639

Browse files
committed
CSV-71 - Add convenience Methods to CSVLexer
Added methods to Lexer parent class (updated CSVLexer to follow) git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1303882 13f79535-47bb-0310-9956-ffa450edef68
1 parent fdfe508 commit 1ae3639

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/main/java/org/apache/commons/csv/Lexer.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
*/
2626
abstract class Lexer {
2727

28+
private final boolean isEncapsulating;
29+
private final boolean isEscaping;
30+
private final boolean isCommentEnabled;
31+
32+
private final char delimiter;
33+
private final char escape;
34+
private final char encapsulator;
35+
private final char commmentStart;
36+
37+
2838
final CSVFormat format;
2939

3040
/** The input stream */
@@ -33,6 +43,13 @@ abstract class Lexer {
3343
Lexer(CSVFormat format, ExtendedBufferedReader in) {
3444
this.format = format;
3545
this.in = in;
46+
this.isEncapsulating = format.isEncapsulating();
47+
this.isEscaping = format.isEscaping();
48+
this.isCommentEnabled = format.isCommentingEnabled();
49+
this.delimiter = format.getDelimiter();
50+
this.escape = format.getEscape();
51+
this.encapsulator = format.getEncapsulator();
52+
this.commmentStart = format.getCommentStart();
3653
}
3754

3855
int getLineNumber() {
@@ -98,4 +115,20 @@ boolean isEndOfFile(int c) {
98115
}
99116

100117
abstract Token nextToken(Token reusableToken) throws IOException;
118+
119+
boolean isDelimiter(int c) {
120+
return c == delimiter;
121+
}
122+
123+
boolean isEscape(int c) {
124+
return isEscaping && c == escape;
125+
}
126+
127+
boolean isEncapsulator(int c) {
128+
return isEncapsulating && c == encapsulator;
129+
}
130+
131+
boolean isCommentStart(int c) {
132+
return isCommentEnabled && c == commmentStart;
133+
}
101134
}

0 commit comments

Comments
 (0)