added XML escape method.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3146 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-04-17 01:15:20 +00:00
1 parent 318fb582a8
commit 6793b72fec
2 files changed
+19

No files matched your search

+15
View File
@@ -392,6 +392,21 @@ public class Util {
return buf.toString();
}
public static String xmlEscape(String text) {
StringBuffer buf = new StringBuffer(text.length()+64);
for( int i=0; i<text.length(); i++ ) {
char ch = text.charAt(i);
if(ch=='<')
buf.append("&lt;");
else
if(ch=='&')
buf.append("&amp;");
else
buf.append(ch);
}
return buf.toString();
}
private static char toDigit(int n) {
char ch = Character.forDigit(n,16);
if(ch>='a') ch = (char)(ch-'a'+'A');