From 1e68361b25ca2e0d72c4319d4156e5055a86f8fb Mon Sep 17 00:00:00 2001 From: Vhati Date: Mon, 16 Sep 2013 09:59:12 -0400 Subject: [PATCH] Added getLastPosition() to the sloppy parser --- .../modmanager/core/SloppyXMLParser.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java b/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java index 58b7c92..8ae6718 100644 --- a/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java +++ b/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java @@ -77,6 +77,8 @@ public class SloppyXMLParser { private JDOMFactory factory; + private int pos = -1; + public SloppyXMLParser() { this( null ); @@ -111,7 +113,7 @@ public class SloppyXMLParser { Parent parentNode = rootNode; int sLen = s.length(); int lastPos = -1; - int pos = 0; + pos = 0; int[] lastLineAndCol = new int[] {0, 0}; // Counts \n's and chars after the last \n. String tmp = null; Matcher m = declPtn.matcher( s ); @@ -427,7 +429,7 @@ public class SloppyXMLParser { /** * Returns lineNum and colNum for a position in text. * 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. * * @param pos a 0-based offset @@ -453,4 +455,18 @@ public class SloppyXMLParser { 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; + } }