/** * strips a subset of HTML that tends to appear in descriptions generated by Groundspeak Builder */ public static String removeHtml(String s) { if (s == null) return ""; StringBuffer sb = new StringBuffer(s.length()); replace(s, "<BR>", "\n", sb); replace(sb.toString(), " ", " ", sb); replace(sb.toString(), "<", "<", sb); replace(sb.toString(), ">", ">", sb); replace(sb.toString(), "&", "&", sb); return sb.toString(); }
private static void replace(String source, String pattern, String replace, StringBuffer builder) { int pos = 0; int pl = pattern.length(); builder.delete(0, builder.length()); while (pos < source.length()) { int np = source.indexOf(pattern, pos); if (np == -1) break; builder.append(source.substring(pos, np)); builder.append(replace); pos = np + pl; } builder.append(source.substring(pos)); }