|
|
@@ -372,8 +372,6 @@ public class ReplaceRegExp extends Task { |
|
|
w = new BufferedWriter(w); |
|
|
w = new BufferedWriter(w); |
|
|
|
|
|
|
|
|
StringBuffer linebuf = new StringBuffer(); |
|
|
StringBuffer linebuf = new StringBuffer(); |
|
|
String line = null; |
|
|
|
|
|
String res = null; |
|
|
|
|
|
int c; |
|
|
int c; |
|
|
boolean hasCR = false; |
|
|
boolean hasCR = false; |
|
|
|
|
|
|
|
|
@@ -383,14 +381,8 @@ public class ReplaceRegExp extends Task { |
|
|
if (c == '\r') { |
|
|
if (c == '\r') { |
|
|
if (hasCR) { |
|
|
if (hasCR) { |
|
|
// second CR -> EOL + possibly empty line |
|
|
// 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'); |
|
|
w.write('\r'); |
|
|
|
|
|
|
|
|
linebuf = new StringBuffer(); |
|
|
linebuf = new StringBuffer(); |
|
|
@@ -401,14 +393,8 @@ public class ReplaceRegExp extends Task { |
|
|
} |
|
|
} |
|
|
} else if (c == '\n') { |
|
|
} else if (c == '\n') { |
|
|
// LF -> EOL |
|
|
// 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) { |
|
|
if (hasCR) { |
|
|
w.write('\r'); |
|
|
w.write('\r'); |
|
|
hasCR = false; |
|
|
hasCR = false; |
|
|
@@ -419,14 +405,8 @@ public class ReplaceRegExp extends Task { |
|
|
} else { // any other char |
|
|
} else { // any other char |
|
|
if ((hasCR) || (c < 0)) { |
|
|
if ((hasCR) || (c < 0)) { |
|
|
// Mac-style linebreak or EOF (or both) |
|
|
// 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) { |
|
|
if (hasCR) { |
|
|
w.write('\r'); |
|
|
w.write('\r'); |
|
|
hasCR = false; |
|
|
hasCR = false; |
|
|
@@ -536,12 +516,15 @@ public class ReplaceRegExp extends Task { |
|
|
|
|
|
|
|
|
private boolean multilineReplace(Reader r, Writer w, int options) |
|
|
private boolean multilineReplace(Reader r, Writer w, int options) |
|
|
throws IOException { |
|
|
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); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|