Skip to content

Commit

Permalink
Use the same internal name as LineNumberReader
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 15, 2024
1 parent 5c73cdc commit e5fa9c9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class ExtendedBufferedReader extends BufferedReader {
private int lastChar = UNDEFINED;

/** The count of EOLs (CR/LF/CRLF) seen so far */
private long eolCounter;
private long lineNumber;

/** The position, which is the number of characters read so far */
private long position;
Expand Down Expand Up @@ -77,9 +77,9 @@ public void close() throws IOException {
long getCurrentLineNumber() {
// Check if we are at EOL or EOF or just starting
if (lastChar == CR || lastChar == LF || lastChar == UNDEFINED || lastChar == EOF) {
return eolCounter; // counter is accurate
return lineNumber; // counter is accurate
}
return eolCounter + 1; // Allow for counter being incremented only at EOL
return lineNumber + 1; // Allow for counter being incremented only at EOL
}

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ public int read() throws IOException {
final int current = super.read();
if (current == CR || current == LF && lastChar != CR ||
current == EOF && lastChar != CR && lastChar != LF && lastChar != EOF) {
eolCounter++;
lineNumber++;
}
lastChar = current;
position++;
Expand All @@ -162,10 +162,10 @@ public int read(final char[] buf, final int offset, final int length) throws IOE
final char ch = buf[i];
if (ch == LF) {
if (CR != (i > offset ? buf[i - 1] : lastChar)) {
eolCounter++;
lineNumber++;
}
} else if (ch == CR) {
eolCounter++;
lineNumber++;
}
}
lastChar = buf[offset + len - 1];
Expand All @@ -180,7 +180,7 @@ public int read(final char[] buf, final int offset, final int length) throws IOE
* Gets the next line, dropping the line terminator(s). This method should only be called when processing a
* comment, otherwise, information can be lost.
* <p>
* Increments {@link #eolCounter} and updates {@link #position}.
* Increments {@link #lineNumber} and updates {@link #position}.
* </p>
* <p>
* Sets {@link #lastChar} to {@code Constants.EOF} at EOF, otherwise the last EOL character.
Expand Down

0 comments on commit e5fa9c9

Please sign in to comment.