@Test public void testJs() { assertThat(Functions.js(null), is("")); assertThat(Functions.js(""), is("")); assertThat(Functions.js("a"), is("a")); assertThat(Functions.js("'"), is("\\'")); assertThat(Functions.js("\""), is("\\\"")); assertThat(Functions.js("\\"), is("\\\\")); assertThat(Functions.js("/"), is("\\/")); assertThat(Functions.js("<"), is("\\x3c")); assertThat(Functions.js(">"), is("\\x3e")); assertThat(Functions.js("\r"), is("\\r")); assertThat(Functions.js("\n"), is("\\n")); assertThat(Functions.js("b"), is("b")); }
public static String js(String value) { if (value == null || value.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); switch (ch) { case '\'': result.append("\\'"); break; case '"': result.append("\\\""); break; case '\\': result.append("\\\\"); break; case '/': result.append("\\/"); break; case '<': result.append("\\x3c"); break; case '>': result.append("\\x3e"); break; case '\r': result.append("\\r"); break; case '\n': result.append("\\n"); break; default: result.append(ch); break; } } return result.toString(); }
Functions { public static String js(String value) { if (value == null || value.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); switch (ch) { case '\'': result.append("\\'"); break; case '"': result.append("\\\""); break; case '\\': result.append("\\\\"); break; case '/': result.append("\\/"); break; case '<': result.append("\\x3c"); break; case '>': result.append("\\x3e"); break; case '\r': result.append("\\r"); break; case '\n': result.append("\\n"); break; default: result.append(ch); break; } } return result.toString(); } }
Functions { public static String js(String value) { if (value == null || value.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); switch (ch) { case '\'': result.append("\\'"); break; case '"': result.append("\\\""); break; case '\\': result.append("\\\\"); break; case '/': result.append("\\/"); break; case '<': result.append("\\x3c"); break; case '>': result.append("\\x3e"); break; case '\r': result.append("\\r"); break; case '\n': result.append("\\n"); break; default: result.append(ch); break; } } return result.toString(); } private  Functions(); }
Functions { public static String js(String value) { if (value == null || value.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); switch (ch) { case '\'': result.append("\\'"); break; case '"': result.append("\\\""); break; case '\\': result.append("\\\\"); break; case '/': result.append("\\/"); break; case '<': result.append("\\x3c"); break; case '>': result.append("\\x3e"); break; case '\r': result.append("\\r"); break; case '\n': result.append("\\n"); break; default: result.append(ch); break; } } return result.toString(); } private  Functions(); static String h(Object input); static String u(String value); static String br(String value); static String cut(String value, int length); static String link(String value); static String mapToQuery(Map<String, ?> map); @Deprecated static String mapToQuery(Map<String, ?> map,
            BeanWrapper beanWrapper); static String query(Object params); static String js(String value); static String hjs(String input); }
Functions { public static String js(String value) { if (value == null || value.isEmpty()) { return ""; } StringBuilder result = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); switch (ch) { case '\'': result.append("\\'"); break; case '"': result.append("\\\""); break; case '\\': result.append("\\\\"); break; case '/': result.append("\\/"); break; case '<': result.append("\\x3c"); break; case '>': result.append("\\x3e"); break; case '\r': result.append("\\r"); break; case '\n': result.append("\\n"); break; default: result.append(ch); break; } } return result.toString(); } private  Functions(); static String h(Object input); static String u(String value); static String br(String value); static String cut(String value, int length); static String link(String value); static String mapToQuery(Map<String, ?> map); @Deprecated static String mapToQuery(Map<String, ?> map,
            BeanWrapper beanWrapper); static String query(Object params); static String js(String value); static String hjs(String input);  }