diff --git a/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java b/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java index dfc2e28..de09f34 100644 --- a/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java +++ b/src/main/java/net/vhati/modmanager/core/SloppyXMLParser.java @@ -200,7 +200,10 @@ public class SloppyXMLParser { am.region( am.end(), am.regionEnd() ); } if ( am.regionStart() < attrString.length() ) { - int[] lineAndCol = getLineAndCol( s, pos ); + int nonspacePos = findNextNonspace( s, pos ); + int errorPos = ( (nonspacePos != -1) ? nonspacePos : pos ); + + int[] lineAndCol = getLineAndCol( s, errorPos ); int lineNum = lineAndCol[0]; int colNum = lineAndCol[1]; @@ -236,7 +239,10 @@ public class SloppyXMLParser { } if ( !matchedChunk ) { - int[] lineAndCol = getLineAndCol( s, pos ); + int nonspacePos = findNextNonspace( s, pos ); + int errorPos = ( (nonspacePos != -1) ? nonspacePos : pos ); + + int[] lineAndCol = getLineAndCol( s, errorPos ); int lineNum = lineAndCol[0]; int colNum = lineAndCol[1]; @@ -304,10 +310,24 @@ public class SloppyXMLParser { } + /** + * Returns the position of the next non whitespace character after pos. + * + * Returns -1 if there isn't one. + */ + public int findNextNonspace( CharSequence s, int pos ) { + Matcher nonspaceMatcher = Pattern.compile( "\\S" ).matcher( s ); + if ( nonspaceMatcher.find( pos ) ) + return nonspaceMatcher.start(); + + return -1; + } + + /** * Returns lineNum and colNum for a position in text. */ - private int[] getLineAndCol( CharSequence s, int pos ) { + public int[] getLineAndCol( CharSequence s, int pos ) { Matcher breakMatcher = Pattern.compile( "\n" ).matcher( s ); breakMatcher.region( 0, pos+1 ); int lastBreakPos = -1;