Have to check for comment after dealing with empty lines.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306667 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9ce0716a43
commit
3fd45b5441
|
@ -46,12 +46,6 @@ class CSVLexer extends Lexer {
|
|||
// read the next char and set eol
|
||||
int c = in.read();
|
||||
|
||||
if (isStartOfLine(lastChar) && isCommentStart(c)) {
|
||||
in.readLine();
|
||||
tkn.type = COMMENT;
|
||||
return tkn;
|
||||
}
|
||||
|
||||
/* note: unfortunately isEndOfLine may consumes a character silently.
|
||||
* this has no effect outside of the method. so a simple workaround
|
||||
* is to call 'readAgain' on the stream...
|
||||
|
@ -83,6 +77,12 @@ class CSVLexer extends Lexer {
|
|||
return tkn;
|
||||
}
|
||||
|
||||
if (isStartOfLine(lastChar) && isCommentStart(c)) {
|
||||
in.readLine();
|
||||
tkn.type = COMMENT;
|
||||
return tkn;
|
||||
}
|
||||
|
||||
// important: make sure a new char gets consumed in each iteration
|
||||
while (tkn.type == INVALID) {
|
||||
// ignore whitespaces at beginning of a token
|
||||
|
|
|
@ -58,11 +58,19 @@ public class CSVLexerTest {
|
|||
public void testNextToken2() throws IOException {
|
||||
final String code =
|
||||
"1,2,3,\n"+ // 1
|
||||
"\n"+
|
||||
"\n"+
|
||||
"a,b x,c#no-comment\n"+ // 2
|
||||
"\n"+
|
||||
"\n"+
|
||||
"#foo\n"+ // 3
|
||||
"\n"+ // 4
|
||||
"d,e,#no-comment\n"+ // 5
|
||||
"\n"+
|
||||
"\n"+
|
||||
"# penultimate comment\n"+ // 6
|
||||
"\n"+
|
||||
"\n"+
|
||||
"# Final comment\n"; // 7
|
||||
CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#');
|
||||
assertTrue("Should ignore empty lines", format.isEmptyLinesIgnored());
|
||||
|
|
Loading…
Reference in New Issue