Skip to content

Commit 9114337

Browse files
committed
CSV-70 Improve readability of CSVLexer
Remove unnecessary parameters git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306062 13f79535-47bb-0310-9956-ffa450edef68
1 parent fba5809 commit 9114337

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Token nextToken(Token tkn) throws IOException {
8989
}
9090

9191
// ok, start of token reached: comment, encapsulated, or token
92-
if (isCommentStart(c)) {
92+
if (isCommentStart(c)) { // TODO should only match at start of line
9393
// ignore everything till end of line and continue (incr linecount)
9494
in.readLine();
9595
tkn = nextToken(tkn.reset());
@@ -102,7 +102,7 @@ Token nextToken(Token tkn) throws IOException {
102102
tkn.type = EORECORD;
103103
} else if (isEncapsulator(c)) {
104104
// consume encapsulated token
105-
encapsulatedTokenLexer(tkn, c);
105+
encapsulatedTokenLexer(tkn);
106106
} else if (isEndOfFile(c)) {
107107
// end of file return EOF()
108108
//noop: tkn.content.append("");
@@ -150,7 +150,7 @@ private Token simpleTokenLexer(Token tkn, int c) throws IOException {
150150
tkn.type = TOKEN;
151151
break;
152152
} else if (isEscape(c)) {
153-
tkn.content.append((char) readEscape(c));
153+
tkn.content.append((char) readEscape());
154154
} else {
155155
tkn.content.append((char) c);
156156
}
@@ -174,20 +174,20 @@ private Token simpleTokenLexer(Token tkn, int c) throws IOException {
174174
* Whitespaces before and after an encapsulated token are ignored.
175175
*
176176
* @param tkn the current token
177-
* @param c the current character
178177
* @return a valid token object
179178
* @throws IOException on invalid state
180179
*/
181-
private Token encapsulatedTokenLexer(Token tkn, int c) throws IOException {
180+
private Token encapsulatedTokenLexer(Token tkn) throws IOException {
182181
// save current line
183182
int startLineNumber = getLineNumber();
184183
// ignore the given delimiter
185184
// assert c == delimiter;
185+
int c;
186186
while (true) {
187187
c = in.read();
188188

189189
if (isEscape(c)) {
190-
tkn.content.append((char) readEscape(c));
190+
tkn.content.append((char) readEscape());
191191
} else if (isEncapsulator(c)) {
192192
if (isEncapsulator(in.lookAhead())) {
193193
// double or escaped encapsulator -> add single encapsulator to token

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ int getLineNumber() {
6060
return in.getLineNumber();
6161
}
6262

63-
int readEscape(int c) throws IOException {
63+
int readEscape() throws IOException {
6464
// assume c is the escape char (normally a backslash)
65-
c = in.read();
65+
int c = in.read();
6666
switch (c) {
6767
case 'r':
6868
return '\r';

src/test/java/org/apache/commons/csv/CSVLexer1.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private Token simpleTokenLexer(Token tkn, int c) throws IOException {
159159
tkn.isReady = true;
160160
break;
161161
} else if (c == format.getEscape()) {
162-
tkn.content.append((char) readEscape(c));
162+
tkn.content.append((char) readEscape());
163163
} else {
164164
tkn.content.append((char) c);
165165
}
@@ -196,7 +196,7 @@ private Token encapsulatedTokenLexer(Token tkn, int c) throws IOException {
196196
c = in.read();
197197

198198
if (c == format.getEscape()) {
199-
tkn.content.append((char) readEscape(c));
199+
tkn.content.append((char) readEscape());
200200
} else if (c == format.getEncapsulator()) {
201201
if (in.lookAhead() == format.getEncapsulator()) {
202202
// double or escaped encapsulator -> add single encapsulator to token

0 commit comments

Comments
 (0)