diff options
author | Roman Shevchenko <roman.shevchenko@jetbrains.com> | 2014-06-27 13:55:49 +0200 |
---|---|---|
committer | Roman Shevchenko <roman.shevchenko@jetbrains.com> | 2014-06-27 13:55:49 +0200 |
commit | 9ae885c9ecc37a76373dfb1391992b61841b2b8f (patch) | |
tree | 2c5a32d8f7f6b65868deaaea4bf491576a4793d5 /src | |
parent | 4df7866a5c5ef56c763f844848d24438bb4555e4 (diff) | |
download | fernflower-9ae885c9ecc37a76373dfb1391992b61841b2b8f.tar fernflower-9ae885c9ecc37a76373dfb1391992b61841b2b8f.tar.gz fernflower-9ae885c9ecc37a76373dfb1391992b61841b2b8f.tar.lz fernflower-9ae885c9ecc37a76373dfb1391992b61841b2b8f.tar.xz fernflower-9ae885c9ecc37a76373dfb1391992b61841b2b8f.zip |
escape non-printable Unicode characters in literals
Diffstat (limited to 'src')
-rw-r--r-- | src/de/fernflower/modules/decompiler/exps/ConstExprent.java | 12 | ||||
-rw-r--r-- | src/de/fernflower/util/InterpreterUtil.java | 7 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/de/fernflower/modules/decompiler/exps/ConstExprent.java b/src/de/fernflower/modules/decompiler/exps/ConstExprent.java index 2d63fcb..b01bf69 100644 --- a/src/de/fernflower/modules/decompiler/exps/ConstExprent.java +++ b/src/de/fernflower/modules/decompiler/exps/ConstExprent.java @@ -27,8 +27,7 @@ import de.fernflower.struct.gen.VarType; import de.fernflower.util.InterpreterUtil; public class ConstExprent extends Exprent { - - private static final HashMap<Integer, String> escapes = new HashMap<Integer, String>(); + private static final HashMap<Integer, String> escapes = new HashMap<Integer, String>(); static { escapes.put(new Integer(0x8), "\\b"); /* \u0008: backspace BS */ @@ -114,10 +113,11 @@ public class ConstExprent extends Exprent { Integer val = (Integer)value; String ret = escapes.get(val); if(ret == null) { - if(!ascii || val.intValue() >= 32 && val.intValue() < 127) { - ret = String.valueOf((char)val.intValue()); + char c = (char)val.intValue(); + if(c >= 32 && c < 127 || !ascii && InterpreterUtil.isPrintableUnicode(c)) { + ret = String.valueOf(c); } else { - ret = InterpreterUtil.charToUnicodeLiteral(val); + ret = InterpreterUtil.charToUnicodeLiteral(c); } } return "\'"+ret+"\'"; @@ -263,7 +263,7 @@ public class ConstExprent extends Exprent { buffer.append("\\\'"); break; default: - if(!ascii || (c >= 32 && c < 127)) { + if(c >= 32 && c < 127 || !ascii && InterpreterUtil.isPrintableUnicode(c)) { buffer.append(c); } else { buffer.append(InterpreterUtil.charToUnicodeLiteral(c)); diff --git a/src/de/fernflower/util/InterpreterUtil.java b/src/de/fernflower/util/InterpreterUtil.java index ffba76a..6f418a2 100644 --- a/src/de/fernflower/util/InterpreterUtil.java +++ b/src/de/fernflower/util/InterpreterUtil.java @@ -138,10 +138,15 @@ public class InterpreterUtil { return false; } + public static boolean isPrintableUnicode(char c) { + int t = Character.getType(c); + return t != Character.UNASSIGNED && t != Character.LINE_SEPARATOR && t != Character.PARAGRAPH_SEPARATOR && + t != Character.CONTROL && t != Character.FORMAT && t != Character.PRIVATE_USE && t != Character.SURROGATE; + } + public static String charToUnicodeLiteral(int value) { String sTemp = Integer.toHexString(value); sTemp = ("0000"+sTemp).substring(sTemp.length()); - return "\\u"+sTemp; } |