Index: src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java
===================================================================
RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java,v
retrieving revision 1.9.2.5
diff -u -r1.9.2.5 ReplaceRegExp.java
--- src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java	24 Jun 2002 02:28:10 -0000	1.9.2.5
+++ src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java	20 Sep 2002 15:50:20 -0000
@@ -323,18 +323,80 @@
                 Project.MSG_VERBOSE);
 
             if (byline) {
-                LineNumberReader lnr = new LineNumberReader(br);
+                StringBuffer linebuf = new StringBuffer();
                 String line = null;
+                String res = null;
+                int c;
+                boolean hasCR = false;
 
-                while ((line = lnr.readLine()) != null) {
-                    String res = doReplace(regex, subs, line, options);
+                do {
+                    c = br.read();
 
-                    if (!res.equals(line)) {
-                        changes = true;
+                    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;
+                            }
+
+                            pw.print(res);
+                            pw.print('\r');
+
+                            linebuf.setLength(0);
+                            // hasCR is still true (for the second one)
+                        }
+                        else {
+                            // first CR in this line
+                            hasCR = true;
+                        }
+                    }
+                    else if (c == '\n') {
+                        // LF -> EOL
+                        line = linebuf.toString();
+                        res  = doReplace(regex, subs, line, options);
+
+                        if (!res.equals(line)) {
+                            changes = true;
+                        }
+
+                        pw.print(res);
+                        if (hasCR) {
+                            pw.print('\r');
+                            hasCR = false;
+                        }
+                        pw.print('\n');
+
+                        linebuf.setLength(0);
                     }
+                    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;
+                            }
+
+                            pw.print(res);
+                            if (hasCR) {
+                                pw.print('\r');
+                                hasCR = false;
+                            }
 
-                    pw.println(res);
+                            linebuf.setLength(0);
+                        }
+
+                        if (c >= 0) {
+                            linebuf.append((char) c);
+                        }
+                    }
                 }
+                while (c >= 0);
+
                 pw.flush();
             } else {
                 int flen = (int) f.length();
