From 4ec387882da55d5d1d86c2312a6254b6befe89d0 Mon Sep 17 00:00:00 2001 From: "JesusFreke@JesusFreke.com" Date: Sat, 20 Jun 2009 20:14:15 +0000 Subject: [PATCH] changed the logic that generates escaped strings to always use the /uxxxx format, instead of the 3 digital octal escape git-svn-id: https://smali.googlecode.com/svn/trunk@177 55b6fa8a-2a1e-11de-a435-ffa8d773f76a --- .../java/org/jf/dexlib/util/Utf8Utils.java | 45 +++++-------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/dexlib/src/main/java/org/jf/dexlib/util/Utf8Utils.java b/dexlib/src/main/java/org/jf/dexlib/util/Utf8Utils.java index d0a45756..35db9838 100644 --- a/dexlib/src/main/java/org/jf/dexlib/util/Utf8Utils.java +++ b/dexlib/src/main/java/org/jf/dexlib/util/Utf8Utils.java @@ -165,49 +165,26 @@ public final class Utf8Utils { for (int i = 0; i < len; i++) { char c = value.charAt(i); + if ((c >= ' ') && (c < 0x7f)) { if ((c == '\'') || (c == '\"') || (c == '\\')) { sb.append('\\'); } sb.append(c); + continue; } else if (c <= 0x7f) { switch (c) { - case '\n': sb.append("\\n"); break; - case '\r': sb.append("\\r"); break; - case '\t': sb.append("\\t"); break; - default: { - /* - * Represent the character as an octal escape. - * If the next character is a valid octal - * digit, disambiguate by using the - * three-digit form. - */ - char nextChar = - (i < (len - 1)) ? value.charAt(i + 1) : 0; - boolean displayZero = - (nextChar >= '0') && (nextChar <= '7'); - sb.append('\\'); - for (int shift = 6; shift >= 0; shift -= 3) { - char outChar = (char) (((c >> shift) & 7) + '0'); - if ((outChar != '0') || displayZero) { - sb.append(outChar); - displayZero = true; - } - } - if (! displayZero) { - // Ironic edge case: The original value was 0. - sb.append('0'); - } - break; - } + case '\n': sb.append("\\n"); continue; + case '\r': sb.append("\\r"); continue; + case '\t': sb.append("\\t"); continue; } - } else { - sb.append("\\u"); - sb.append(Character.forDigit(c >> 12, 16)); - sb.append(Character.forDigit((c >> 8) & 0x0f, 16)); - sb.append(Character.forDigit((c >> 4) & 0x0f, 16)); - sb.append(Character.forDigit(c & 0x0f, 16)); } + + sb.append("\\u"); + sb.append(Character.forDigit(c >> 12, 16)); + sb.append(Character.forDigit((c >> 8) & 0x0f, 16)); + sb.append(Character.forDigit((c >> 4) & 0x0f, 16)); + sb.append(Character.forDigit(c & 0x0f, 16)); } return sb.toString();