Clover coverage report - PMD - 3.7
Coverage timestamp: Wed May 31 2006 09:25:59 EDT
file stats: LOC: 119   Methods: 4
NCLOC: 73   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StringUtil.java 61.5% 79.2% 100% 74.4%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd.util;
 5   
 6    public class StringUtil {
 7   
 8    private static final String[] ENTITIES;
 9   
 10    static {
 11  3 ENTITIES = new String[256 - 126];
 12  3 for (int i = 126; i <= 255; i++) {
 13  390 ENTITIES[i - 126] = "&#" + i + ';';
 14    }
 15    }
 16   
 17  3 public static String replaceString(String d, char oldChar, String newString) {
 18  3 String fixedNew = newString;
 19  3 if (fixedNew == null) {
 20  1 fixedNew = "";
 21    }
 22  3 StringBuffer desc = new StringBuffer();
 23  3 int index = d.indexOf(oldChar);
 24  3 int last = 0;
 25  3 while (index != -1) {
 26  6 desc.append(d.substring(last, index));
 27  6 desc.append(fixedNew);
 28  6 last = index + 1;
 29  6 index = d.indexOf(oldChar, last);
 30    }
 31  3 desc.append(d.substring(last));
 32  3 return desc.toString();
 33    }
 34   
 35  5 public static String replaceString(String inputString, String oldString, String newString) {
 36  5 String fixedNew = newString;
 37  5 if (fixedNew == null) {
 38  0 fixedNew = "";
 39    }
 40  5 StringBuffer desc = new StringBuffer();
 41  5 int index = inputString.indexOf(oldString);
 42  5 int last = 0;
 43  5 while (index != -1) {
 44  1 desc.append(inputString.substring(last, index));
 45  1 desc.append(fixedNew);
 46  1 last = index + oldString.length();
 47  1 index = inputString.indexOf(oldString, last);
 48    }
 49  5 desc.append(inputString.substring(last));
 50  5 return desc.toString();
 51    }
 52   
 53    /**
 54    * Appends to a StringBuffer the String src where non-ASCII and
 55    * XML special chars are escaped.
 56    *
 57    * @param buf The destination XML stream
 58    * @param src The String to append to the stream
 59    */
 60  21 public static void appendXmlEscaped(StringBuffer buf, String src) {
 61  21 appendXmlEscaped(buf, src, System.getProperty("net.sourceforge.pmd.supportUTF8", "no").equals("yes"));
 62    }
 63   
 64  21 private static void appendXmlEscaped(StringBuffer buf, String src, boolean supportUTF8) {
 65  21 char c;
 66  21 for (int i = 0; i < src.length(); i++) {
 67  103 c = src.charAt(i);
 68  103 if (c > '~') {// 126
 69  0 if (!supportUTF8) {
 70  0 if (c <= 255) {
 71  0 buf.append(ENTITIES[c - 126]);
 72    } else {
 73  0 buf.append("&u").append(Integer.toHexString(c)).append(';');
 74    }
 75    } else {
 76  0 buf.append(c);
 77    }
 78  103 } else if (c == '&')
 79  0 buf.append("&amp;");
 80  103 else if (c == '"')
 81  0 buf.append("&quot;");
 82  103 else if (c == '<')
 83  0 buf.append("&lt;");
 84  103 else if (c == '>')
 85  0 buf.append("&gt;");
 86    else
 87  103 buf.append(c);
 88    }
 89    }
 90   
 91    /* public static void appendXmlEscaped2(StringBuffer buf, String src) {
 92    int l = src.length();
 93    char c;
 94    for (int i = 0; i < l; i++) {
 95    c = src.charAt(i);
 96    if (c <= 32) {
 97    buf.append(c);
 98    } else if (c > '~') {// 126
 99    if (c <= 255)
 100    buf.append(ENTITIES[c - 126]);
 101    else
 102   
 103    buf.append("&u").append(Integer.toHexString(c)).append(';');
 104    } else if (c == 38)
 105    buf.append("&amp;");
 106    else if (c == 34)
 107    buf.append("&quot;");
 108    else if (c == 39)
 109    buf.append("&apos;");
 110    else if (c == 60)
 111    buf.append("&lt;");
 112    else if (c == 62)
 113    buf.append("&gt;");
 114    else
 115    buf.append(c);
 116    }
 117    }
 118    */
 119    }