[Htmlparser-cvs] htmlparser/src/org/htmlparser/lexer Lexer.java,1.18,1.19 Page.java,1.23,1.24 PageIn
Brought to you by:
derrickoswald
From: <der...@us...> - 2003-11-04 01:25:06
|
Update of /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer In directory sc8-pr-cvs1:/tmp/cvs-serv25697/lexer Modified Files: Lexer.java Page.java PageIndex.java Log Message: Made visiting order the same order as on the page. The 'shouldRecurseSelf' boolean of NodeVisitor could probably be removed since it doesn't make much sense any more. Fixed StringBean, which was still looking for end tags with names starting with a slash, i.e. "/SCRIPT", silly beany. Added some debugging support to the lexer, you can easily base a breakpoint on line number. Index: Lexer.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/Lexer.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Lexer.java 28 Oct 2003 03:04:18 -0000 1.18 --- Lexer.java 4 Nov 2003 01:25:02 -0000 1.19 *************** *** 79,89 **** /** * Creates a new instance of a Lexer. */ public Lexer () { ! setPage (new Page ("")); ! setCursor (new Cursor (getPage (), 0)); ! setNodeFactory (this); } --- 79,96 ---- /** + * Line number to trigger on. + * This is tested on each <code>nextNode()</code> call, as an aid to debugging. + * Alter this value and set a breakpoint on the line after the test. + * Remember, these line numbers are zero based, while most editors are one based. + * @see #nextNode + */ + static protected int mDebugLineTrigger = -1; + + /** * Creates a new instance of a Lexer. */ public Lexer () { ! this (new Page ("")); } *************** *** 247,250 **** --- 254,265 ---- Node ret; + // debugging suppport + if (-1 != mDebugLineTrigger) + { + Page page = getPage (); + int lineno = page.row (mCursor); + if (mDebugLineTrigger < lineno) + mDebugLineTrigger = lineno + 1; // trigger on subsequent lines too + } probe = mCursor.dup (); ch = mPage.getCharacter (probe); Index: Page.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/Page.java,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Page.java 29 Oct 2003 03:31:17 -0000 1.23 --- Page.java 4 Nov 2003 01:25:02 -0000 1.24 *************** *** 804,823 **** { int line; int start; int end; line = row (cursor); ! start = mIndex.elementAt (line); ! line++; ! end = mIndex.last (); ! if (end <= line) ! end = mIndex.elementAt (end); ! else end = mSource.mOffset; return (getText (start, end)); } - // todo refactor into common code method: - /** * Get the text line the position of the cursor lies on. --- 804,832 ---- { int line; + int size; int start; int end; line = row (cursor); ! size = mIndex.size (); ! if (line < size) ! { ! start = mIndex.elementAt (line); ! line++; ! if (line <= size) ! end = mIndex.elementAt (line); ! else ! end = mSource.mOffset; ! } ! else // current line ! { ! start = mIndex.elementAt (line - 1); end = mSource.mOffset; + } + + return (getText (start, end)); } /** * Get the text line the position of the cursor lies on. *************** *** 828,844 **** public String getLine (int position) { ! int line; int start; ! int end; ! line = row (position); ! start = mIndex.elementAt (line); ! line++; ! end = mIndex.last (); ! if (end <= line) ! end = mIndex.elementAt (end); else ! end = mSource.mOffset; ! return (getText (start, end)); } } --- 837,868 ---- public String getLine (int position) { ! return (getLine (new Cursor (this, position))); ! } ! ! /** ! * Display some of this page as a string. ! * @return The last few characters the source read in. ! */ ! public String toString () ! { ! StringBuffer buffer; int start; ! String ret; ! if (mSource.mOffset > 0) ! { ! buffer = new StringBuffer (43); ! start = mSource.mOffset - 40; ! if (0 > start) ! start = 0; ! else ! buffer.append ("..."); ! getText (buffer, start, mSource.mOffset); ! ret = buffer.toString (); ! } else ! ret = super.toString (); ! ! return (ret); } } Index: PageIndex.java =================================================================== RCS file: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexer/PageIndex.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** PageIndex.java 26 Oct 2003 19:46:18 -0000 1.12 --- PageIndex.java 4 Nov 2003 01:25:02 -0000 1.13 *************** *** 198,202 **** public int elementAt (int index) { ! return (mIndices[index]); } --- 198,205 ---- public int elementAt (int index) { ! if (index >= mCount) // negative index is handled by array.. below ! throw new IndexOutOfBoundsException ("index " + index + " beyond current limit"); ! else ! return (mIndices[index]); } *************** *** 353,356 **** --- 356,360 ---- * @return The index of the last element. * If this were an array object this would be (object.length - 1). + * For an empty index this will return -1. */ public int last () |