Skip to content

Commit e235b2a

Browse files
committed
Refactor '\r' and '\n' into constants.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1383564 13f79535-47bb-0310-9956-ffa450edef68
1 parent 29944bc commit e235b2a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
*/
3232
class ExtendedBufferedReader extends BufferedReader {
3333

34+
private static final char CR = '\r';
35+
36+
private static final char LF = '\n';
37+
3438
/** The end of stream symbol */
3539
static final int END_OF_STREAM = -1;
3640

@@ -53,7 +57,7 @@ class ExtendedBufferedReader extends BufferedReader {
5357
@Override
5458
public int read() throws IOException {
5559
int current = super.read();
56-
if (current == '\r' || (current == '\n' && lastChar != '\r')) {
60+
if (current == CR || (current == LF && lastChar != CR)) {
5761
lineCounter++;
5862
}
5963
lastChar = current;
@@ -86,11 +90,11 @@ public int read(char[] buf, int offset, int length) throws IOException {
8690

8791
for (int i = offset; i < offset + len; i++) {
8892
char ch = buf[i];
89-
if (ch == '\n') {
90-
if ('\r' != (i > 0 ? buf[i-1]: lastChar)) {
93+
if (ch == LF) {
94+
if (CR != (i > 0 ? buf[i-1]: lastChar)) {
9195
lineCounter++;
9296
}
93-
} else if (ch == '\r') {
97+
} else if (ch == CR) {
9498
lineCounter++;
9599
}
96100
}
@@ -121,7 +125,7 @@ public String readLine() throws IOException {
121125
String line = super.readLine();
122126

123127
if (line != null) {
124-
lastChar = '\n'; // needed for detecting start of line
128+
lastChar = LF; // needed for detecting start of line
125129
lineCounter++;
126130
} else {
127131
lastChar = END_OF_STREAM;

0 commit comments

Comments
 (0)