hillion 01/11/21 07:22:00 Modified: sources/org/apache/batik/css/parser Scanner.java sources/org/apache/batik/parser AbstractParser.java LengthParser.java NumberParser.java test-resources/org/apache/batik/parser unitTesting.xml Log: Fixed line/column numbers in parsers. Revision Changes Path 1.10 +28 -21 xml-batik/sources/org/apache/batik/css/parser/Scanner.java Index: Scanner.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/parser/Scanner.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Scanner.java 2001/11/13 16:23:17 1.9 +++ Scanner.java 2001/11/21 15:22:00 1.10 @@ -16,7 +16,7 @@ * units. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: Scanner.java,v 1.9 2001/11/13 16:23:17 hillion Exp $ + * @version $Id: Scanner.java,v 1.10 2001/11/21 15:22:00 hillion Exp $ */ public class Scanner { @@ -33,7 +33,7 @@ /** * The current column. */ - protected int column = 1; + protected int column; /** * The current char. @@ -1199,12 +1199,10 @@ * end of stream has been reached. */ protected int nextChar() throws IOException { - if ((readPosition == readCount) && (!fillReadBuffer())) { + if (readPosition == readCount && !fillReadBuffer()) { return current = -1; } - current = readBuffer[readPosition++]; - if (current != 10) { column++; } else { @@ -1212,6 +1210,8 @@ column = 1; } + current = readBuffer[readPosition++]; + if (position == buffer.length) { char[] t = new char[position * 3 / 2]; System.arraycopy(buffer, 0, t, 0, position); @@ -1221,11 +1221,12 @@ return buffer[position++] = (char)current; } - protected final boolean fillReadBuffer() throws IOException { + private boolean fillReadBuffer() throws IOException { if (readCount != 0) { if (readPosition == readCount) { readBuffer[0] = readBuffer[readCount-1]; - readCount=readPosition=1; + readCount = 1; + readPosition = 1; } else { // we keep the last char in our readBuffer. System.arraycopy(readBuffer, readPosition-1, readBuffer, 0, @@ -1236,46 +1237,52 @@ } // No reader so can't extend... - if (reader == null) + if (reader == null) { return (readCount != readPosition); + } // remember where the fill starts... - int src=readCount-1; - if (src < 0) src = 0; + int src = readCount - 1; + if (src < 0) { + src = 0; + } // Refill the readBuffer... int read = reader.read(readBuffer, readCount, readBuffer.length-readCount); - if (read == -1) - return (readCount != readPosition); - - readCount+=read; // add in chars read. + if (read == -1) { + return readCount != readPosition; + } - + readCount += read; // add in chars read. collapseCRNL(src); // Now collapse cr/nl... - return (readCount != readPosition); + return readCount != readPosition; } - protected final void collapseCRNL(int src) { + private void collapseCRNL(int src) { // Now collapse cr/nl... - while (src<readCount) { + while (src < readCount) { if (readBuffer[src] != 13) { src++; } else { readBuffer[src] = 10; src++; - if (src>=readCount) break; + if (src >= readCount) { + break; + } if (readBuffer[src] == 10) { // We now need to collapse some of the chars to // eliminate cr/nl pairs. This is where we do it... int dst = src; // start writing where this 10 is src++; // skip reading this 10. - while (src<readCount) { + while (src < readCount) { if (readBuffer[src] == 13) { readBuffer[dst++] = 10; src++; - if (src>=readCount) break; + if (src >= readCount) { + break; + } if (readBuffer[src] == 10) { src++; } 1.5 +82 -47 xml-batik/sources/org/apache/batik/parser/AbstractParser.java Index: AbstractParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/AbstractParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- AbstractParser.java 2001/11/08 23:02:43 1.4 +++ AbstractParser.java 2001/11/21 15:22:00 1.5 @@ -24,7 +24,7 @@ * and error handling methods. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: AbstractParser.java,v 1.4 2001/11/08 23:02:43 deweese Exp $ + * @version $Id: AbstractParser.java,v 1.5 2001/11/21 15:22:00 hillion Exp $ */ public abstract class AbstractParser implements Parser { @@ -58,7 +58,7 @@ /** * The current column. */ - protected int column = 1; + protected int column; /** * The buffer. @@ -80,7 +80,6 @@ */ protected int current; - /** * Returns the current character value. */ @@ -143,8 +142,7 @@ public void parse(String s) throws ParseException { reader = null; buffer = s.toCharArray(); - position=0; - count=buffer.length; + count = buffer.length; collapseCRNL(0, count); doParse(); @@ -158,23 +156,27 @@ protected final void collapseCRNL(int src, int end) { // Now collapse cr/nl... - while(src<end) { + while (src < end) { if (buffer[src] != 13) { src++; } else { buffer[src] = 10; src++; - if (src>=end) break; + if (src >= end) { + break; + } if (buffer[src] == 10) { // We now need to collapse some of the chars to // eliminate cr/nl pairs. This is where we do it... int dst = src; // start writing where this 10 is src++; // skip reading this 10. - while (src<end) { + while (src < end) { if (buffer[src] == 13) { buffer[dst++] = 10; src++; - if (src>=end) break; + if (src >= end) { + break; + } if (buffer[src] == 10) { src++; } @@ -193,23 +195,27 @@ try { if (count != 0) { if (position == count) { - buffer[0] = buffer[count-1]; - count=position=1; + buffer[0] = buffer[count - 1]; + count = 1; + position = 1; } else { // we keep the last char in our buffer. - System.arraycopy(buffer, position-1, buffer, 0, - count-position+1); - count = (count-position)+1; + System.arraycopy(buffer, position - 1, buffer, 0, + count - position + 1); + count = (count - position) + 1; position = 1; } } - if (reader == null) + if (reader == null) { return (count != position); - + } + // remember where the fill starts... - int src=count-1; - if (src < 0) src = 0; + int src = count - 1; + if (src < 0) { + src = 0; + } // Refill the buffer... int read = reader.read(buffer, count, buffer.length-count); @@ -217,13 +223,12 @@ return (count != position); } - count+=read; // add in chars read. + count += read; // add in chars read. collapseCRNL(src, count); } catch (IOException e) { errorHandler.error (new ParseException - (createErrorMessage("io.exception", null), - e)); + (createErrorMessage("io.exception", null), e)); } return (count != position); } @@ -233,19 +238,19 @@ * value. */ protected void read() { - if ((position == count) && (!fillBuffer())) { + if (position == count && !fillBuffer()) { current = -1; return; } - current = buffer[position++]; - if (current == 10) { line++; column = 1; } else { column++; } + + current = buffer[position++]; } /** @@ -294,16 +299,24 @@ case 0xA: } for (;;) { - if ((position == count) && (!fillBuffer())) { + if (position == count && !fillBuffer()) { current = -1; return; } + + if (current == 10) { + line++; + column = 1; + } else { + column++; + } + current = buffer[position++]; switch (current) { - default: return; - case 0x20: case 0x09: column++; break; - case 0x0D: case 0x0A: line++; column=0; break; + default: + return; + case 0x20: case 0x09: case 0x0D: case 0x0A: } } } @@ -312,51 +325,73 @@ * Skips the whitespaces and an optional comma. */ protected void skipCommaSpaces() { - // Check current char... switch (current) { - default: return; - case 0x20: case 0x09: case 0x0D: case 0x0A: break; // nl/cr, spc, tab + default: + return; + case 0x20: case 0x09: case 0x0D: case 0x0A: + break; case ',': - // for a comma just eat rest of ws. for(;;) { - if ((position == count) && (!fillBuffer())) { + if (position == count && !fillBuffer()) { current = -1; return; } + + if (current == 10) { + line++; + column = 1; + } else { + column++; + } + current = buffer[position++]; + switch (current) { - default: return; - case 0x20: case 0x09: column++; break; // space/tab - case 0x0D: case 0x0A: line++; column=0; break; // nl/cr + default: + return; + case 0x20: case 0x09: case 0x0D: case 0x0A: } } } for(;;) { - // After current char we need to take care to increment line - // and column... - if ((position == count) && (!fillBuffer())) { + if (position == count && !fillBuffer()) { current = -1; return; } + + if (current == 10) { + line++; + column = 1; + } else { + column++; + } + current = buffer[position++]; switch (current) { - default: return; - case 0x20: case 0x09: column++; break; // space tab - case 0x0D: case 0x0A: line++; column=0; break; // nl cr + default: + return; + case 0x20: case 0x09: case 0x0D: case 0x0A: + break; case ',': - // for a comma just eat rest of ws. for(;;) { - if ((position == count) && (!fillBuffer())) { + if (position == count && !fillBuffer()) { current = -1; return; } + + if (current == 10) { + line++; + column = 1; + } else { + column++; + } current = buffer[position++]; switch (current) { - default: return; - case 0x20: case 0x09: column++; break; - case 0x0D: case 0x0A: line++; column=0; break; + default: + return; + case 0x20: case 0x09: case 0x0D: case 0x0A: } } } 1.7 +11 -41 xml-batik/sources/org/apache/batik/parser/LengthParser.java Index: LengthParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/LengthParser.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- LengthParser.java 2001/11/19 13:39:56 1.6 +++ LengthParser.java 2001/11/21 15:22:00 1.7 @@ -15,7 +15,7 @@ * values. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: LengthParser.java,v 1.6 2001/11/19 13:39:56 hillion Exp $ + * @version $Id: LengthParser.java,v 1.7 2001/11/21 15:22:00 hillion Exp $ */ public class LengthParser extends AbstractParser { @@ -93,14 +93,11 @@ current = -1; break; } - current = buffer[position++]; column++; + current = buffer[position++]; } m1: switch (current) { - case 10: - line++; - column = 1; default: reportError("character.unexpected", new Object[] { new Integer(current) }); @@ -115,16 +112,13 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break l; - case 10: - line++; - column = 1; default: break m1; case '0': @@ -144,13 +138,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: break l; case '0': case '1': case '2': case '3': case '4': @@ -163,13 +154,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } m2: switch (current) { - case 10: - line++; - column = 1; default: case 'e': case 'E': if (!mantRead) { @@ -185,17 +173,14 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } expAdj--; switch (current) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break l; - case 10: - line++; - column = 1; default: break m2; case '0': @@ -213,13 +198,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: break l; case '0': case '1': case '2': case '3': case '4': @@ -237,13 +219,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: reportError("character.unexpected", new Object[] { new Integer(current) }); @@ -270,13 +249,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: reportError("character.unexpected", new Object[] { new Integer(current) }); @@ -294,16 +270,13 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break l; - case 10: - line++; - column = 1; default: break en; case '0': @@ -320,13 +293,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: break l; case '0': case '1': case '2': case '3': case '4': 1.5 +30 -51 xml-batik/sources/org/apache/batik/parser/NumberParser.java Index: NumberParser.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/parser/NumberParser.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- NumberParser.java 2001/11/19 13:39:56 1.4 +++ NumberParser.java 2001/11/21 15:22:00 1.5 @@ -15,7 +15,7 @@ * This class represents a parser with support for numbers. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: NumberParser.java,v 1.4 2001/11/19 13:39:56 hillion Exp $ + * @version $Id: NumberParser.java,v 1.5 2001/11/21 15:22:00 hillion Exp $ */ public abstract class NumberParser extends AbstractParser { @@ -41,14 +41,11 @@ current = -1; break; } - current = buffer[position++]; column++; + current = buffer[position++]; } m1: switch (current) { - case 10: - line++; - column = 1; default: reportError("character.unexpected", new Object[] { new Integer(current) }); @@ -63,8 +60,8 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { case '1': case '2': case '3': case '4': @@ -72,9 +69,6 @@ break l; case '.': case 'e': case 'E': break m1; - case 10: - line++; - column = 1; default: return 0f; case '0': @@ -94,13 +88,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: break l; case '0': case '1': case '2': case '3': case '4': @@ -113,13 +104,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } m2: switch (current) { - case 10: - line++; - column = 1; default: case 'e': case 'E': if (!mantRead) { @@ -135,17 +123,14 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } expAdj--; switch (current) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break l; - case 10: - line++; - column = 1; default: if (!mantRead) { return 0f; @@ -166,13 +151,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: break l; case '0': case '1': case '2': case '3': case '4': @@ -187,13 +169,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: reportError("character.unexpected", new Object[] { new Integer(current) }); @@ -204,13 +183,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: reportError("character.unexpected", new Object[] { new Integer(current) }); @@ -228,16 +204,13 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break l; - case 10: - line++; - column = 1; default: break en; case '0': @@ -254,13 +227,10 @@ if (position == count && !fillBuffer()) { current = -1; } else { - current = buffer[position++]; column++; + current = buffer[position++]; } switch (current) { - case 10: - line++; - column = 1; default: break l; case '0': case '1': case '2': case '3': case '4': @@ -282,20 +252,29 @@ return buildFloat(mant, exp); } + /** + * Computes a float from mantissa and exponent. + */ public static float buildFloat(int mant, int exp) { - if ((exp < -125) || (mant==0)) return 0f; + if (exp < -125 || mant == 0) { + return 0f; + } + if (exp > 128) { - if (mant > 0) return Float.POSITIVE_INFINITY; - else return Float.NEGATIVE_INFINITY; + return (mant > 0) + ? Float.POSITIVE_INFINITY + : Float.NEGATIVE_INFINITY; } - if (exp == 0) return mant; + if (exp == 0) { + return mant; + } - if (mant >= 1<<26) + if (mant >= 1 << 26) { mant++; // round up trailing bits if they will be dropped. + } - if (exp > 0) return mant*pow10[exp]; - else return mant/pow10[-exp]; + return (exp > 0) ? mant * pow10[exp] : mant / pow10[-exp]; } /** @@ -303,8 +282,8 @@ */ private static final float pow10[] = new float [128]; static { - for (int i=0; i<pow10.length; i++) { - pow10[i] = (float)Math.pow(10, i); - } + for (int i = 0; i < pow10.length; i++) { + pow10[i] = (float)Math.pow(10, i); + } }; } 1.3 +2 -2 xml-batik/test-resources/org/apache/batik/parser/unitTesting.xml Index: unitTesting.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/parser/unitTesting.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- unitTesting.xml 2001/11/19 13:39:56 1.2 +++ unitTesting.xml 2001/11/21 15:22:00 1.3 @@ -8,7 +8,7 @@ <!-- ========================================================================= --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: unitTesting.xml,v 1.2 2001/11/19 13:39:56 hillion Exp $ --> +<!-- @version $Id: unitTesting.xml,v 1.3 2001/11/21 15:22:00 hillion Exp $ --> <!-- ========================================================================= --> <testSuite id="parser.unitTesting" name="org.apache.batik.parser package - Unit Testing"> @@ -336,7 +336,7 @@ </test> <test id="transformParser10" class="org.apache.batik.parser.TransformListParserTest"> - <arg class="java.lang.String" value="scale(1),skewX(2) translate(3,4)" /> + <arg class="java.lang.String" value="scale(1) , skewX(2) translate(3,4)" /> <arg class="java.lang.String" value="scale(1.0) skewX(2.0) translate(3.0, 4.0)"/> </test>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]