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
This commit is contained in:
Gary D. Gregory 2012-09-11 19:17:25 +00:00
parent 29944bcec1
commit e235b2a63c
1 changed files with 9 additions and 5 deletions

View File

@ -31,6 +31,10 @@ import java.io.Reader;
*/
class ExtendedBufferedReader extends BufferedReader {
private static final char CR = '\r';
private static final char LF = '\n';
/** The end of stream symbol */
static final int END_OF_STREAM = -1;
@ -53,7 +57,7 @@ class ExtendedBufferedReader extends BufferedReader {
@Override
public int read() throws IOException {
int current = super.read();
if (current == '\r' || (current == '\n' && lastChar != '\r')) {
if (current == CR || (current == LF && lastChar != CR)) {
lineCounter++;
}
lastChar = current;
@ -86,11 +90,11 @@ class ExtendedBufferedReader extends BufferedReader {
for (int i = offset; i < offset + len; i++) {
char ch = buf[i];
if (ch == '\n') {
if ('\r' != (i > 0 ? buf[i-1]: lastChar)) {
if (ch == LF) {
if (CR != (i > 0 ? buf[i-1]: lastChar)) {
lineCounter++;
}
} else if (ch == '\r') {
} else if (ch == CR) {
lineCounter++;
}
}
@ -121,7 +125,7 @@ class ExtendedBufferedReader extends BufferedReader {
String line = super.readLine();
if (line != null) {
lastChar = '\n'; // needed for detecting start of line
lastChar = LF; // needed for detecting start of line
lineCounter++;
} else {
lastChar = END_OF_STREAM;