JSP - htmlspecialchars() htmlentities() PHP like function - version 2.0
The search has continued and no solution has been found yet.
As I was not pleased with the performance of my previous approach I worked out the following one:
StringBuffer sb = new StringBuffer();
for(int i=0; i<content.length(); i++) {
char c = content.charAt(i);
switch (c) {
case ‘<’ :
sb.append(”<”);
break;
case ‘>’ :
sb.append(”>”);
break;
case ‘&’ :
sb.append(”&”);
break;
case ‘”‘ :
sb.append(”"”);
break;
case ‘\” :
sb.append(”'”);
break;
default:
sb.append(c);
}
}
content = sb.toString();
This verision is a lot faster then the previous one. On the page source from the slashdot site this version performed in under 8ms while the other one had it’s best performance in 20ms (usually in the range of 30ms).

thanks, the code is great!