1 16 package org.apache.myfaces.renderkit.html.util; 17 18 19 20 21 24 public abstract class UnicodeEncoder 25 { 26 29 public static String encode (String string) 30 { 31 return encode(string, false, true); 32 } 33 34 37 public static String encode (String string, boolean encodeNewline) 38 { 39 return encode(string, encodeNewline, true); 40 } 41 42 48 public static String encode (String string, 49 boolean encodeNewline, 50 boolean encodeSubsequentBlanksToNbsp) 51 { 52 if (string == null) 53 { 54 return ""; 55 } 56 57 StringBuffer sb = new StringBuffer (); char c; 59 for (int i = 0; i < string.length (); ++i) 60 { 61 c = string.charAt(i); 62 if (((int)c) >= 0x80) 63 { 64 sb.append("&#" + ((int)c) + ";"); 66 } 67 else 68 { 69 sb.append(c); 70 } 71 } 72 73 return sb.toString(); 74 } 75 76 77 } 78 | Popular Tags |