Skip to content

Commit dd26201

Browse files
committed
CSV-81 Token.Type.isReady could perhaps be removed
Not removed, but only set on EOF if there is data to return git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1303988 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8bba58d commit dd26201

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Token nextToken(Token tkn) throws IOException {
6565
// reached end of file without any content (empty line at the end)
6666
if (isEndOfFile(c)) {
6767
tkn.type = EOF;
68+
// don't set tkn.isReady here because no content
6869
return tkn;
6970
}
7071
}
@@ -73,11 +74,12 @@ Token nextToken(Token tkn) throws IOException {
7374
// did we reach eof during the last iteration already ? EOF
7475
if (isEndOfFile(lastChar) || (!isDelimiter(lastChar) && isEndOfFile(c))) {
7576
tkn.type = EOF;
77+
// don't set tkn.isReady here because no content
7678
return tkn;
7779
}
7880

7981
// important: make sure a new char gets consumed in each iteration
80-
while (!tkn.isReady && tkn.type != EOF) {
82+
while (tkn.type == INVALID) {
8183
// ignore whitespaces at beginning of a token
8284
if (leadingSpacesIgnored) {
8385
while (isWhitespace(c) && !eol) {
@@ -94,20 +96,18 @@ Token nextToken(Token tkn) throws IOException {
9496
} else if (isDelimiter(c)) {
9597
// empty token return TOKEN("")
9698
tkn.type = TOKEN;
97-
tkn.isReady = true;
9899
} else if (eol) {
99100
// empty token return EORECORD("")
100101
//noop: tkn.content.append("");
101102
tkn.type = EORECORD;
102-
tkn.isReady = true;
103103
} else if (isEncapsulator(c)) {
104104
// consume encapsulated token
105105
encapsulatedTokenLexer(tkn, c);
106106
} else if (isEndOfFile(c)) {
107107
// end of file return EOF()
108108
//noop: tkn.content.append("");
109109
tkn.type = EOF;
110-
tkn.isReady = true;
110+
tkn.isReady = true; // there is data at EOF
111111
} else {
112112
// next token must be a simple token
113113
// add removed blanks when not ignoring whitespace chars...
@@ -139,17 +139,15 @@ private Token simpleTokenLexer(Token tkn, int c) throws IOException {
139139
if (isEndOfLine(c)) {
140140
// end of record
141141
tkn.type = EORECORD;
142-
tkn.isReady = true;
143142
break;
144143
} else if (isEndOfFile(c)) {
145144
// end of file
146145
tkn.type = EOF;
147-
tkn.isReady = true;
146+
tkn.isReady = true; // There is data at EOF
148147
break;
149148
} else if (isDelimiter(c)) {
150149
// end of token
151150
tkn.type = TOKEN;
152-
tkn.isReady = true;
153151
break;
154152
} else if (isEscape(c)) {
155153
tkn.content.append((char) readEscape(c));
@@ -201,16 +199,14 @@ private Token encapsulatedTokenLexer(Token tkn, int c) throws IOException {
201199
c = in.read();
202200
if (isDelimiter(c)) {
203201
tkn.type = TOKEN;
204-
tkn.isReady = true;
205202
return tkn;
206203
} else if (isEndOfFile(c)) {
207204
tkn.type = EOF;
208-
tkn.isReady = true;
205+
tkn.isReady = true; // There is data at EOF
209206
return tkn;
210207
} else if (isEndOfLine(c)) {
211208
// ok eo token reached
212209
tkn.type = EORECORD;
213-
tkn.isReady = true;
214210
return tkn;
215211
} else if (!isWhitespace(c)) {
216212
// error invalid char between token and next delimiter

0 commit comments

Comments
 (0)