diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 61898428ac..3b2ac54dbb 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,6 +1,7 @@ ?? ??, 201? - 4.3: Add options --ignore-literals and --ignore-identifiers to the CPD command line task, thanks to Cd-Man +Fixed character reference in xml report - thanks to Seko September 14, 2011 - 4.2.6: Fixed bug 2920057 - False + : CloseRessource whith an external getter diff --git a/pmd/src/net/sourceforge/pmd/util/StringUtil.java b/pmd/src/net/sourceforge/pmd/util/StringUtil.java index bfb2f65855..d67729ffe1 100644 --- a/pmd/src/net/sourceforge/pmd/util/StringUtil.java +++ b/pmd/src/net/sourceforge/pmd/util/StringUtil.java @@ -11,17 +11,9 @@ public class StringUtil { public static final String[] EMPTY_STRINGS = new String[0]; private static final boolean supportsUTF8 = System.getProperty("net.sourceforge.pmd.supportUTF8", "no").equals("yes"); - private static final String[] ENTITIES; - - static { - ENTITIES = new String[256 - 126]; - for (int i = 126; i <= 255; i++) { - ENTITIES[i - 126] = "&#" + i + ';'; - } - } public static String replaceString(String original, char oldChar, String newString) { - + String fixedNew = newString == null ? "" : newString; StringBuffer desc = new StringBuffer(); @@ -38,9 +30,9 @@ public class StringUtil { } public static String replaceString(String original, String oldString, String newString) { - + String fixedNew = newString == null ? "" : newString; - + StringBuffer desc = new StringBuffer(); int index = original.indexOf(oldString); int last = 0; @@ -70,20 +62,16 @@ public class StringUtil { encoded = StringUtil.replaceString(encoded, '<', "<"); return StringUtil.replaceString(encoded, '>', ">"); } - + // TODO - unify the method above with the one below - + private static void appendXmlEscaped(StringBuffer buf, String src, boolean supportUTF8) { char c; for (int i = 0; i < src.length(); i++) { c = src.charAt(i); if (c > '~') {// 126 if (!supportUTF8) { - if (c <= 255) { - buf.append(ENTITIES[c - 126]); - } else { - buf.append("&u").append(Integer.toHexString(c)).append(';'); - } + buf.append("&#x").append(Integer.toHexString(c)).append(';'); } else { buf.append(c); } @@ -116,7 +104,7 @@ public class StringUtil { if (source == null || source.length() == 0) { return EMPTY_STRINGS; } - + int delimiterCount = 0; int length = source.length(); char[] chars = source.toCharArray(); @@ -141,16 +129,16 @@ public class StringUtil { return results; } - + /** * Much more efficient than StringTokenizer. - * + * * @param str String * @param separator char * @return String[] */ public static String[] substringsOf(String str, String separator) { - + if (str == null || str.length() == 0) { return EMPTY_STRINGS; } @@ -171,8 +159,8 @@ public class StringUtil { list.add(str.substring(currPos)); return list.toArray(new String[list.size()]); } - - + + /** * Copies the elements returned by the iterator onto the string buffer * each delimited by the separator. @@ -182,11 +170,11 @@ public class StringUtil { * @param separator String */ public static void asStringOn(StringBuffer sb, Iterator iter, String separator) { - + if (!iter.hasNext()) return; - + sb.append(iter.next()); - + while (iter.hasNext()) { sb.append(separator); sb.append(iter.next()); @@ -195,70 +183,70 @@ public class StringUtil { /** * Return the length of the shortest string in the array. * If any one of them is null then it returns 0. - * + * * @param strings String[] * @return int */ public static int lengthOfShortestIn(String[] strings) { - + int minLength = Integer.MAX_VALUE; - + for (int i=0; i