mirror of
https://github.com/apache/commons-csv.git
synced 2025-02-09 19:45:38 +00:00
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
This commit is contained in:
parent
9114337075
commit
0a0f3bbd36
@ -92,7 +92,7 @@ class CSVLexer extends Lexer {
|
||||
if (isCommentStart(c)) { // TODO should only match at start of line
|
||||
// ignore everything till end of line and continue (incr linecount)
|
||||
in.readLine();
|
||||
tkn = nextToken(tkn.reset());
|
||||
tkn.type = COMMENT;
|
||||
} else if (isDelimiter(c)) {
|
||||
// empty token return TOKEN("")
|
||||
tkn.type = TOKEN;
|
||||
|
@ -154,6 +154,8 @@ public class CSVParser implements Iterable<CSVRecord> {
|
||||
break;
|
||||
case INVALID:
|
||||
throw new IOException("(line " + getLineNumber() + ") invalid parse sequence");
|
||||
case COMMENT: // Ignored currently
|
||||
break;
|
||||
}
|
||||
} while (reusableToken.type == TOKEN);
|
||||
|
||||
|
@ -41,7 +41,10 @@ class Token {
|
||||
EOF,
|
||||
|
||||
/** Token with content when end of a line is reached. */
|
||||
EORECORD
|
||||
EORECORD,
|
||||
|
||||
/** Token is a comment line */
|
||||
COMMENT
|
||||
}
|
||||
|
||||
/** Token type */
|
||||
|
@ -76,6 +76,7 @@ public class CSVLexerTest {
|
||||
assertTokenEquals(TOKEN, "a", parser.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "b x", parser.nextToken(new Token()));
|
||||
assertTokenEquals(EORECORD, "c", parser.nextToken(new Token()));
|
||||
assertTokenEquals(COMMENT, "", parser.nextToken(new Token()));
|
||||
assertTokenEquals(EORECORD, "", parser.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "d", parser.nextToken(new Token()));
|
||||
assertTokenEquals(TOKEN, "e", parser.nextToken(new Token()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user