commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1383564 - /commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Date Tue, 11 Sep 2012 19:17:25 GMT
Author: ggregory
Date: Tue Sep 11 19:17:25 2012
New Revision: 1383564

URL: http://svn.apache.org/viewvc?rev=1383564&view=rev
Log:
Refactor '\r' and '\n' into constants.

Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java?rev=1383564&r1=1383563&r2=1383564&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
(original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Tue Sep 11 19:17:25 2012
@@ -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 Buf
     @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 Buf
 
             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 Buf
         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;



Mime
View raw message