You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2014/03/14 20:44:55 UTC

svn commit: r1577676 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java

Author: bodewig
Date: Fri Mar 14 19:44:54 2014
New Revision: 1577676

URL: http://svn.apache.org/r1577676
Log:
small refactoring

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java?rev=1577676&r1=1577675&r2=1577676&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java Fri Mar 14 19:44:54 2014
@@ -372,8 +372,6 @@ public class ReplaceRegExp extends Task 
                         w = new BufferedWriter(w);
 
                         StringBuffer linebuf = new StringBuffer();
-                        String line = null;
-                        String res = null;
                         int c;
                         boolean hasCR = false;
 
@@ -383,14 +381,8 @@ public class ReplaceRegExp extends Task 
                             if (c == '\r') {
                                 if (hasCR) {
                                     // second CR -> EOL + possibly empty line
-                                    line = linebuf.toString();
-                                    res  = doReplace(regex, subs, line, options);
-
-                                    if (!res.equals(line)) {
-                                        changes = true;
-                                    }
-
-                                    w.write(res);
+                                    changes |= replaceAndWrite(linebuf.toString(),
+                                                               w, options);
                                     w.write('\r');
 
                                     linebuf = new StringBuffer();
@@ -401,14 +393,8 @@ public class ReplaceRegExp extends Task 
                                 }
                             } else if (c == '\n') {
                                 // LF -> EOL
-                                line = linebuf.toString();
-                                res  = doReplace(regex, subs, line, options);
-
-                                if (!res.equals(line)) {
-                                    changes = true;
-                                }
-
-                                w.write(res);
+                                changes |= replaceAndWrite(linebuf.toString(),
+                                                           w, options);
                                 if (hasCR) {
                                     w.write('\r');
                                     hasCR = false;
@@ -419,14 +405,8 @@ public class ReplaceRegExp extends Task 
                             } else { // any other char
                                 if ((hasCR) || (c < 0)) {
                                     // Mac-style linebreak or EOF (or both)
-                                    line = linebuf.toString();
-                                    res  = doReplace(regex, subs, line, options);
-
-                                    if (!res.equals(line)) {
-                                        changes = true;
-                                    }
-
-                                    w.write(res);
+                                    changes |= replaceAndWrite(linebuf.toString(),
+                                                               w, options);
                                     if (hasCR) {
                                         w.write('\r');
                                         hasCR = false;
@@ -536,12 +516,15 @@ public class ReplaceRegExp extends Task 
 
     private boolean multilineReplace(Reader r, Writer w, int options)
         throws IOException {
-        String buf = FileUtils.safeReadFully(r);
-        String res = doReplace(regex, subs, buf, options);
-        w.write(res);
-        return !res.equals(buf);
+        return replaceAndWrite(FileUtils.safeReadFully(r), w, options);
     }
 
+    private boolean replaceAndWrite(String s, Writer w, int options)
+        throws IOException {
+        String res = doReplace(regex, subs, s, options);
+        w.write(res);
+        return !res.equals(s);
+    }
 }