File tree Expand file tree Collapse file tree
main/java/org/apache/commons/csv
test/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,12 +46,6 @@ Token nextToken(Token tkn) throws IOException {
4646 // read the next char and set eol
4747 int c = in .read ();
4848
49- if (isStartOfLine (lastChar ) && isCommentStart (c )) {
50- in .readLine ();
51- tkn .type = COMMENT ;
52- return tkn ;
53- }
54-
5549 /* note: unfortunately isEndOfLine may consumes a character silently.
5650 * this has no effect outside of the method. so a simple workaround
5751 * is to call 'readAgain' on the stream...
@@ -83,6 +77,12 @@ Token nextToken(Token tkn) throws IOException {
8377 return tkn ;
8478 }
8579
80+ if (isStartOfLine (lastChar ) && isCommentStart (c )) {
81+ in .readLine ();
82+ tkn .type = COMMENT ;
83+ return tkn ;
84+ }
85+
8686 // important: make sure a new char gets consumed in each iteration
8787 while (tkn .type == INVALID ) {
8888 // ignore whitespaces at beginning of a token
Original file line number Diff line number Diff line change @@ -58,11 +58,19 @@ public void testNextToken1() throws IOException {
5858 public void testNextToken2 () throws IOException {
5959 final String code =
6060 "1,2,3,\n " + // 1
61+ "\n " +
62+ "\n " +
6163 "a,b x,c#no-comment\n " + // 2
64+ "\n " +
65+ "\n " +
6266 "#foo\n " + // 3
6367 "\n " + // 4
6468 "d,e,#no-comment\n " + // 5
69+ "\n " +
70+ "\n " +
6571 "# penultimate comment\n " + // 6
72+ "\n " +
73+ "\n " +
6674 "# Final comment\n " ; // 7
6775 CSVFormat format = CSVFormat .DEFAULT .withCommentStart ('#' );
6876 assertTrue ("Should ignore empty lines" , format .isEmptyLinesIgnored ());
You can’t perform that action at this time.
0 commit comments