Sorry for the multiple changes! -Matt --- [EMAIL PROTECTED] wrote: > mbenson 2005/03/04 14:29:32 > > Modified: src/main/org/apache/tools/ant/filters > FixCrLfFilter.java > Log: > 1. Remove unused private inner class. > 2. Fix loop introduced by a seemingly innocent > logic change :( > 3. Fix bug that caused extra EOFs when input > already contained EOF. > 4. Make instances constructed with a Reader > usable. > > Revision Changes Path > 1.3 +27 -37 > ant/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java > > Index: FixCrLfFilter.java > > =================================================================== > RCS file: > /home/cvs/ant/src/main/org/apache/tools/ant/filters/FixCrLfFilter.java,v > retrieving revision 1.2 > retrieving revision 1.3 > diff -u -r1.2 -r1.3 > --- FixCrLfFilter.java 4 Mar 2005 16:45:37 -0000 > 1.2 > +++ FixCrLfFilter.java 4 Mar 2005 22:29:32 -0000 > 1.3 > @@ -79,6 +79,7 @@ > private AddAsisRemove tabs; > private boolean javafiles = false; > private boolean fixlast = true; > + private boolean initialized = false; > > /** > * Constructor for "dummy" instances. > @@ -263,6 +264,7 @@ > } > // Add missing EOF character > in = (ctrlz == AddAsisRemove.ADD) ? new > AddEofFilter(in) : in; > + initialized = true; > } > > /** > @@ -274,7 +276,10 @@ > * @exception IOException if the underlying > stream throws an IOException > * during reading. > */ > - public final int read() throws IOException { > + public synchronized final int read() throws > IOException { > + if (!initialized) { > + initInternalFilters(); > + } > return in.read(); > } > > @@ -552,16 +557,24 @@ > > if (normalizedEOL == 0) { > int numEOL = 0; > - > + boolean atEnd = false; > switch (thisChar) { > case CTRLZ: > + int c = super.read(); > + if (c == -1) { > + atEnd = true; > + if (fixLast && > !previousWasEOL) { > + numEOL = 1; > + push(thisChar); > + } > + } else { > + push(c); > + } > + break; > case -1: > + atEnd = true; > if (fixLast && > !previousWasEOL) { > numEOL = 1; > - > - if (thisChar == CTRLZ) { > - push(thisChar); > - } > } > break; > case '\n': > @@ -595,7 +608,7 @@ > } > previousWasEOL = true; > thisChar = read(); > - } else if (thisChar != -1) { > + } else if (!atEnd) { > previousWasEOL = false; > } > } else { > @@ -605,33 +618,6 @@ > } > } > > - private static class FixLastFilter extends > SimpleFilterReader { > - int lastChar = -1; > - char[] eol = null; > - > - public FixLastFilter(Reader in, String > eolString) { > - super(in); > - eol = eolString.toCharArray(); > - } > - > - public int read() throws IOException { > - int thisChar = super.read(); > - // if source is EOF but last > character was NOT eol, return eol > - if (thisChar == -1) { > - switch (lastChar) { > - case '\r': > - case '\n': > - // Return first character of > EOL > - thisChar = eol[0]; > - // Push remaining characters > onto input stream > - push(eol, 1, eol.length - 1); > - } > - } > - lastChar = thisChar; > - return thisChar; > - } > - } > - > private static class AddEofFilter extends > SimpleFilterReader { > int lastChar = -1; > > @@ -643,10 +629,14 @@ > int thisChar = super.read(); > > // if source is EOF but last > character was NOT ctrl-z, return ctrl-z > - if (thisChar == -1 && lastChar != > CTRLZ) { > - thisChar = CTRLZ; > + if (thisChar == -1) { > + if (lastChar != CTRLZ) { > + lastChar = CTRLZ; > + return lastChar; > + } > + } else { > + lastChar = thisChar; > } > - lastChar = thisChar; > return thisChar; > } > } > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > >
__________________________________ Celebrate Yahoo!'s 10th Birthday! Yahoo! Netrospective: 100 Moments of the Web http://birthday.yahoo.com/netrospective/ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]