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
This commit is contained in:
parent
05b5c8ef48
commit
e922bf949a
|
@ -49,12 +49,19 @@ class CSVLexer extends Lexer {
|
||||||
* is to call 'readAgain' on the stream...
|
* is to call 'readAgain' on the stream...
|
||||||
*/
|
*/
|
||||||
int c = in.read();
|
int c = in.read();
|
||||||
|
|
||||||
|
if (isStartOfLine(lastChar) && isCommentStart(c)) {
|
||||||
|
in.readLine();
|
||||||
|
tkn.type = COMMENT;
|
||||||
|
return tkn;
|
||||||
|
}
|
||||||
|
|
||||||
boolean eol = isEndOfLine(c);
|
boolean eol = isEndOfLine(c);
|
||||||
c = in.readAgain();
|
c = in.readAgain();
|
||||||
|
|
||||||
// empty line detection: eol AND (last char was EOL or beginning)
|
// empty line detection: eol AND (last char was EOL or beginning)
|
||||||
if (emptyLinesIgnored) {
|
if (emptyLinesIgnored) {
|
||||||
while (eol && (lastChar == '\n' || lastChar == '\r' || lastChar == ExtendedBufferedReader.UNDEFINED)) {
|
while (eol && isStartOfLine(lastChar)) {
|
||||||
// go on char ahead ...
|
// go on char ahead ...
|
||||||
lastChar = c;
|
lastChar = c;
|
||||||
c = in.read();
|
c = in.read();
|
||||||
|
@ -86,12 +93,8 @@ class CSVLexer extends Lexer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, start of token reached: comment, encapsulated, or token
|
// ok, start of token reached: encapsulated, or token
|
||||||
if (isCommentStart(c)) { // TODO should only match at start of line
|
if (isDelimiter(c)) {
|
||||||
// ignore everything till end of line and continue (incr linecount)
|
|
||||||
in.readLine();
|
|
||||||
tkn.type = COMMENT;
|
|
||||||
} else if (isDelimiter(c)) {
|
|
||||||
// empty token return TOKEN("")
|
// empty token return TOKEN("")
|
||||||
tkn.type = TOKEN;
|
tkn.type = TOKEN;
|
||||||
} else if (eol) {
|
} else if (eol) {
|
||||||
|
|
Loading…
Reference in New Issue