From: adam Date: Thu, 25 Mar 2004 12:23:28 +0000 (+0000) Subject: added two hacks to XML.java to support Doc.java X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=commitdiff_plain;h=e325174951e80031a26b25e0c4d211b73a4ba252 added two hacks to XML.java to support Doc.java darcs-hash:20040325122328-5007d-9512fc9c902ac93743f34571cee5a0969af7e96d.gz --- diff --git a/src/org/ibex/util/XML.java b/src/org/ibex/util/XML.java index e148fb9..d0775c7 100644 --- a/src/org/ibex/util/XML.java +++ b/src/org/ibex/util/XML.java @@ -70,6 +70,7 @@ public abstract class XML private Reader in; private char[] buf; private int off; + private int base; // base+off == distance into the stream private int len; private Element current; @@ -87,13 +88,15 @@ public abstract class XML if (current == null) current = new Element(); } - /** Returns the line number at the beginning of the last process call. */ public int getLine() { return line; } /** Returns the column number at the beginning of the last process call. */ public int getCol() { return col; } + /** Returns the global file offset at the beginning of the last process call. */ + public int getGlobalOffset() { return base + off; } + /** * Parse given input and call the abstract event functions. * @@ -691,12 +694,14 @@ public abstract class XML } else if (off >= min) { // moving offset data to start will leave enough free space on the end System.arraycopy(buf, off, buf, 0, len); + base += off; off = 0; } else { // buffer size will have to be increased char[] newbuf = new char[buf.length * 2]; System.arraycopy(buf, off, newbuf, 0, len); buf = newbuf; + base += off; off = 0; } @@ -774,7 +779,6 @@ public abstract class XML protected Exn[] errors = new Exn[] {}; - /** Parent of current element. */ public Element getParent() { return parent; } @@ -825,10 +829,23 @@ public abstract class XML /** Current number of attributes in the element. */ public int getAttrLen() { return len; } + /** Poor performance, but easier to use when speed is not a concern */ + public Hash getAttrHash() { + Hash ret = new Hash(getAttrLen() * 2, 3); + for(int i=0; i