1 2 24 25 26 27 28 package com.lutris.util; 29 30 50 public final class HtmlEncoder { 51 52 58 public static String encode(String s) { 59 char [] htmlChars = s.toCharArray(); 60 StringBuffer encodedHtml = new StringBuffer (); 61 for (int i=0; i<htmlChars.length; i++) { 62 switch(htmlChars[i]) { 63 case '<': 64 encodedHtml.append("<"); 65 break; 66 case '>': 67 encodedHtml.append(">"); 68 break; 69 case '&': 70 encodedHtml.append("&"); 71 break; 72 case '\'': 73 encodedHtml.append("'"); 74 break; 75 case '"': 76 encodedHtml.append("""); 77 break; 78 case '\\': 79 encodedHtml.append("\"); 80 break; 81 case (char)133: 82 encodedHtml.append("…"); 83 break; 84 default: 85 encodedHtml.append(htmlChars[i]); 86 break; 87 } 88 } 89 return encodedHtml.toString(); 90 } 91 } 92 | Popular Tags |