Add a config flag to disable whitespace trimming

This commit is contained in:
Keaton Taylor
2023-11-20 12:11:47 +02:00
parent 11c29c366d
commit 30f5b2de79
5 changed files with 160 additions and 7 deletions

View File

@@ -20,6 +20,8 @@ public class XMLTokener extends JSONTokener {
*/
public static final java.util.HashMap<String, Character> entity;
private static XMLParserConfiguration configuration = XMLParserConfiguration.ORIGINAL;;
static {
entity = new java.util.HashMap<String, Character>(8);
entity.put("amp", XML.AMP);
@@ -45,6 +47,15 @@ public class XMLTokener extends JSONTokener {
super(s);
}
public XMLTokener(Reader r, XMLParserConfiguration configuration) {
super(r);
XMLTokener.configuration = configuration;
}
public XMLTokener(String s, XMLParserConfiguration configuration) {
super(s);
XMLTokener.configuration = configuration;
}
/**
* Get the text in the CDATA block.
* @return The string up to the <code>]]&gt;</code>.
@@ -83,7 +94,7 @@ public class XMLTokener extends JSONTokener {
StringBuilder sb;
do {
c = next();
} while (Character.isWhitespace(c));
} while (Character.isWhitespace(c) && configuration.shouldTrimWhiteSpace());
if (c == 0) {
return null;
}
@@ -97,7 +108,9 @@ public class XMLTokener extends JSONTokener {
}
if (c == '<') {
back();
return sb.toString().trim();
if (configuration.shouldTrimWhiteSpace()) {
return sb.toString().trim();
} else return sb.toString();
}
if (c == '&') {
sb.append(nextEntity(c));