diff --git a/JavaClass.java b/JavaClass.java index d3831d6..fc1d0c1 100644 --- a/JavaClass.java +++ b/JavaClass.java @@ -184,8 +184,6 @@ void appendField (Field field, FieldNode asmField, Document doc, Element parent) if (asmField == null) // this happens to couple of fields on java.awt.font.TextAttribute, java.lang.Double/Float and so on. System.err.println ("!!!!! WARNING!!! null ASM FieldNode for " + field); - //else if (field.isEnumConstant ()) - // e.setAttribute ("value", field.getName ()); else if (asmField.value != null) { String type = e.getAttribute ("type"); boolean isPublic = Modifier.isPublic (mods); @@ -238,7 +236,7 @@ else if (type == "boolean") else if (type == "java.lang.String") { String value = (String) asmField.value; if (value != null) - e.setAttribute ("value", "\"" + value.replace ("\\", "\\\\") + "\""); + e.setAttribute ("value", "\"" + escapeLiteral (value.replace ("\\", "\\\\")) + "\""); } else if (Modifier.isStatic (mods) && e.getAttribute ("type").endsWith ("[]")) e.setAttribute ("value", "null"); @@ -252,6 +250,24 @@ else if (!Modifier.isStatic (mods) && e.getAttribute ("type").endsWith ("[]")) parent.appendChild (e); } + String escapeLiteral (String s) + { + for (int i = 0; i < s.length (); i++) + if (s.charAt (i) < 0x20 || 0xFF <= s.charAt (i)) + return doEscapeLiteral (new StringBuilder (s), i); + return s; + } + + String doEscapeLiteral (StringBuilder s, int i) + { + s.replace (i, i + 1, String.format ("\\u%1$x04" + (int) s.charAt (i))); + i += 4; + for (;i < s.length (); i++) + if (s.charAt (i) < 0x20 || 0xFF <= s.charAt (i)) + return doEscapeLiteral (s, i); + return s.toString (); + } + void appendMethod (Method method, Document doc, Element parent) { int mods = method.getModifiers (); diff --git a/Start.java b/Start.java index d03a970..6cfdd54 100644 --- a/Start.java +++ b/Start.java @@ -94,7 +94,7 @@ public static void main (String[] args) List jar_paths = new ArrayList (); String out_path = null; List additional_jar_paths = new ArrayList (); - String usage = "Usage: jar2xml --jar= --out= [--javadocpath=] [--droiddocpath=] [--annotations=]"; + String usage = "Usage: jar2xml --jar= [--ref=] --out= [--javadocpath=] [--droiddocpath=] [--annotations=]"; for (String arg : args) { if (arg.startsWith ("--javadocpath=")) {