Skip to content

Commit e922bf9

Browse files
committed
CSV-84 Clarify comment handling
Fix code so comment only detected at start of a line git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306325 13f79535-47bb-0310-9956-ffa450edef68
1 parent 05b5c8e commit e922bf9

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@ Token nextToken(Token tkn) throws IOException {
4949
* is to call 'readAgain' on the stream...
5050
*/
5151
int c = in.read();
52+
53+
if (isStartOfLine(lastChar) && isCommentStart(c)) {
54+
in.readLine();
55+
tkn.type = COMMENT;
56+
return tkn;
57+
}
58+
5259
boolean eol = isEndOfLine(c);
5360
c = in.readAgain();
5461

5562
// empty line detection: eol AND (last char was EOL or beginning)
5663
if (emptyLinesIgnored) {
57-
while (eol && (lastChar == '\n' || lastChar == '\r' || lastChar == ExtendedBufferedReader.UNDEFINED)) {
64+
while (eol && isStartOfLine(lastChar)) {
5865
// go on char ahead ...
5966
lastChar = c;
6067
c = in.read();
@@ -86,12 +93,8 @@ Token nextToken(Token tkn) throws IOException {
8693
}
8794
}
8895

89-
// ok, start of token reached: comment, encapsulated, or token
90-
if (isCommentStart(c)) { // TODO should only match at start of line
91-
// ignore everything till end of line and continue (incr linecount)
92-
in.readLine();
93-
tkn.type = COMMENT;
94-
} else if (isDelimiter(c)) {
96+
// ok, start of token reached: encapsulated, or token
97+
if (isDelimiter(c)) {
9598
// empty token return TOKEN("")
9699
tkn.type = TOKEN;
97100
} else if (eol) {

0 commit comments

Comments
 (0)