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:
Sebastian Bazley 2012-03-28 00:01:43 +00:00
parent 9114337075
commit 0a0f3bbd36
4 changed files with 8 additions and 2 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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 */

View File

@ -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()));