-
- /**
- * Unescapes an XML entity encoding;
- * @param e entity (only the actual entity value, not the preceding & or ending ;
- * @return
- */
- static String unescapeEntity(String e) {
- // validate
- if (e == null || e.isEmpty()) {
- return "";
+ String string = sb.toString();
+ return unescapeEntity(string);
+ }
+
+ /**
+ * Unescapes an XML entity encoding;
+ *
+ * @param e
+ * entity (only the actual entity value, not the preceding & or
+ * ending ;
+ * @return
+ */
+ static String unescapeEntity(String e)
+ {
+ // validate
+ if (e == null || e.isEmpty())
+ {
+ return "";
+ }
+ // if our entity is an encoded unicode point, parse it.
+ if (e.charAt(0) == '#')
+ {
+ int cp;
+ if (e.charAt(1) == 'x')
+ {
+ // hex encoded unicode
+ cp = Integer.parseInt(e.substring(2), 16);
+ }
+ else
+ {
+ // decimal encoded unicode
+ cp = Integer.parseInt(e.substring(1));
+ }
+ return new String(new int[] { cp }, 0, 1);
+ }
+ Character knownEntity = entity.get(e);
+ if (knownEntity == null)
+ {
+ // we don't know the entity so keep it encoded
+ return '&' + e + ';';
+ }
+ return knownEntity.toString();
+ }
+
+ /**
+ * Returns the next XML meta token. This is used for skipping over <!...> and
+ * <?...?> structures.
+ *
+ * @return Syntax characters (<code>< > / = ! ?</code>) are returned as
+ * Character, and strings and names are returned as Boolean. We don't
+ * care what the values actually are.
+ * @throws JSONException
+ * If a string is not properly closed or if the XML is badly
+ * structured.
+ */
+ public Object nextMeta() throws JSONException
+ {
+ char c;
+ char q;
+ do
+ {
+ c = next();
+ } while (Character.isWhitespace(c));
+ switch (c)
+ {
+ case 0:
+ throw syntaxError("Misshaped meta tag");
+ case '<':
+ return XML.LT;
+ case '>':
+ return XML.GT;
+ case '/':
+ return XML.SLASH;
+ case '=':
+ return XML.EQ;
+ case '!':
+ return XML.BANG;
+ case '?':
+ return XML.QUEST;
+ case '"':
+ case '\'':
+ q = c;
+ for (;;)
+ {
+ c = next();
+ if (c == 0)
+ {
+ throw syntaxError("Unterminated string");