1 2 24 25 26 27 28 package com.lutris.util; 29 30 45 public class JavaScriptEncoder { 46 47 53 public static String encode(String s) { 54 char [] scriptChars = s.toCharArray(); 55 StringBuffer encodedScript = new StringBuffer (); 56 for (int i=0; i<scriptChars.length; i++) { 57 switch(scriptChars[i]) { 58 case '\'': 59 encodedScript.append("\\\'"); 60 break; 61 case '\"': 62 encodedScript.append("\\\""); 63 break; 64 case '\\': 65 encodedScript.append("\\\\"); 66 break; 67 default: 68 encodedScript.append(scriptChars[i]); 69 break; 70 } 71 } 72 return encodedScript.toString(); 73 } 74 } 75 | Popular Tags |