Added getLastPosition() to the sloppy parser
This commit is contained in:
parent
ec79b42a92
commit
1e68361b25
1 changed files with 18 additions and 2 deletions
|
@ -77,6 +77,8 @@ public class SloppyXMLParser {
|
||||||
|
|
||||||
private JDOMFactory factory;
|
private JDOMFactory factory;
|
||||||
|
|
||||||
|
private int pos = -1;
|
||||||
|
|
||||||
|
|
||||||
public SloppyXMLParser() {
|
public SloppyXMLParser() {
|
||||||
this( null );
|
this( null );
|
||||||
|
@ -111,7 +113,7 @@ public class SloppyXMLParser {
|
||||||
Parent parentNode = rootNode;
|
Parent parentNode = rootNode;
|
||||||
int sLen = s.length();
|
int sLen = s.length();
|
||||||
int lastPos = -1;
|
int lastPos = -1;
|
||||||
int pos = 0;
|
pos = 0;
|
||||||
int[] lastLineAndCol = new int[] {0, 0}; // Counts \n's and chars after the last \n.
|
int[] lastLineAndCol = new int[] {0, 0}; // Counts \n's and chars after the last \n.
|
||||||
String tmp = null;
|
String tmp = null;
|
||||||
Matcher m = declPtn.matcher( s );
|
Matcher m = declPtn.matcher( s );
|
||||||
|
@ -427,7 +429,7 @@ public class SloppyXMLParser {
|
||||||
/**
|
/**
|
||||||
* Returns lineNum and colNum for a position in text.
|
* Returns lineNum and colNum for a position in text.
|
||||||
* The first line is line 1.
|
* The first line is line 1.
|
||||||
* Line breaks start a new lins as col 0.
|
* Line breaks start a new line as col 0.
|
||||||
* The first char of each line, after the break is col 1.
|
* The first char of each line, after the break is col 1.
|
||||||
*
|
*
|
||||||
* @param pos a 0-based offset
|
* @param pos a 0-based offset
|
||||||
|
@ -453,4 +455,18 @@ public class SloppyXMLParser {
|
||||||
|
|
||||||
return new int[] { breakCount+1, colNum };
|
return new int[] { breakCount+1, colNum };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last character offset this parser was looking at.
|
||||||
|
*
|
||||||
|
* Usually this will be a patch of whitespace prior to unrecognized chars.
|
||||||
|
* This method is a fallback when an unexpected exception doesn't provide
|
||||||
|
* line info.
|
||||||
|
*
|
||||||
|
* @see findNextNonspace(CharSequence s, int pos)
|
||||||
|
*/
|
||||||
|
public int getLastPosition() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue