Skip to content

Commit 0a0f3bb

Browse files
committed
CSV-70 Improve readability of CSVLexer
Introduce COMMENT type git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306064 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9114337 commit 0a0f3bb

4 files changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Token nextToken(Token tkn) throws IOException {
9292
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();
95-
tkn = nextToken(tkn.reset());
95+
tkn.type = COMMENT;
9696
} else if (isDelimiter(c)) {
9797
// empty token return TOKEN("")
9898
tkn.type = TOKEN;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ CSVRecord getRecord() throws IOException {
154154
break;
155155
case INVALID:
156156
throw new IOException("(line " + getLineNumber() + ") invalid parse sequence");
157+
case COMMENT: // Ignored currently
158+
break;
157159
}
158160
} while (reusableToken.type == TOKEN);
159161

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ enum Type {
4141
EOF,
4242

4343
/** Token with content when end of a line is reached. */
44-
EORECORD
44+
EORECORD,
45+
46+
/** Token is a comment line */
47+
COMMENT
4548
}
4649

4750
/** Token type */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void testNextToken2() throws IOException {
7676
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
7777
assertTokenEquals(TOKEN, "b x", parser.nextToken(new Token()));
7878
assertTokenEquals(EORECORD, "c", parser.nextToken(new Token()));
79+
assertTokenEquals(COMMENT, "", parser.nextToken(new Token()));
7980
assertTokenEquals(EORECORD, "", parser.nextToken(new Token()));
8081
assertTokenEquals(TOKEN, "d", parser.nextToken(new Token()));
8182
assertTokenEquals(TOKEN, "e", parser.nextToken(new Token()));

0 commit comments

Comments
 (0)