From 93089b260cd2030d69b3f7113ed643b9af1adcaa Mon Sep 17 00:00:00 2001 From: Sebastian Bazley Date: Wed, 28 Mar 2012 13:40:46 +0000 Subject: [PATCH] Add method for detecting start of line git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306321 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/commons/csv/CSVLexer.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVLexer.java b/src/main/java/org/apache/commons/csv/CSVLexer.java index 254933f0..3c1869f7 100644 --- a/src/main/java/org/apache/commons/csv/CSVLexer.java +++ b/src/main/java/org/apache/commons/csv/CSVLexer.java @@ -49,6 +49,13 @@ class CSVLexer extends Lexer { * is to call 'readAgain' on the stream... */ int c = in.read(); + + if ((lastChar == '\n' || lastChar == '\r' || lastChar == ExtendedBufferedReader.UNDEFINED) && isCommentStart(c)) { + in.readLine(); + tkn.type = COMMENT; + return tkn; + } + boolean eol = isEndOfLine(c); c = in.readAgain(); @@ -86,12 +93,8 @@ class CSVLexer extends Lexer { } } - // ok, start of token reached: comment, encapsulated, or token - if (isCommentStart(c)) { // TODO should only match at start of line - // ignore everything till end of line and continue (incr linecount) - in.readLine(); - tkn.type = COMMENT; - } else if (isDelimiter(c)) { + // ok, start of token reached: encapsulated, or token + if (isDelimiter(c)) { // empty token return TOKEN("") tkn.type = TOKEN; } else if (eol) {