public static String enquote(final String value) { String result = null; if (value != null) { result = "\"" + StringEscapeUtils.escapeJava(value) + "\""; } return result; }
/** * <p> * Escapes the characters in a <code>String</code> using Java String rules to a <code>Writer</code>. * </p> * * <p> * A <code>null</code> string input has no effect. * </p> * * @see #escapeJava(java.lang.String) * @param out Writer to write escaped string into * @param str String to escape values in, may be null * @throws IllegalArgumentException if the Writer is <code>null</code> * @throws IOException if error occurs on underlying Writer */ public static void escapeJava(Writer out, String str) throws IOException { escapeJavaStyleString(out, str, false, false); }
public static String unquote(final String value) { String result = null; if (value != null) { result = value.replaceAll("\"(.*)\"", "$1"); } return StringEscapeUtils.unescapeJava(result); }
/** * <p> * Escapes the characters in a <code>String</code> using Java String rules to a <code>Writer</code>. * </p> * * <p> * A <code>null</code> string input has no effect. * </p> * * @see #escapeJava(java.lang.String) * @param out Writer to write escaped string into * @param str String to escape values in, may be null * @throws IllegalArgumentException if the Writer is <code>null</code> * @throws IOException if error occurs on underlying Writer */ public static void escapeJava(Writer out, String str) throws IOException { escapeJavaStyleString(out, str, false, false); }
public static String unquote(final String value) { String result = null; if (value != null) { result = value.replaceAll("\"(.*)\"", "$1"); } return StringEscapeUtils.unescapeJava(result); }
public static String enquote(final String value) { String result = null; if (value != null) { result = "\"" + StringEscapeUtils.escapeJava(value) + "\""; } return result; }
return escapeJavaStyleString(str, false, false);
/** * <p> * Unescapes any Java literals found in the <code>String</code>. For example, it will turn a sequence of * <code>'\'</code> and <code>'n'</code> into a newline character, unless the <code>'\'</code> is preceded by another * <code>'\'</code>. * </p> * * @param str the <code>String</code> to unescape, may be null * @return a new unescaped <code>String</code>, <code>null</code> if null string input */ public static String unescapeJava(String str) { if (str == null) { return null; } try { StringWriter writer = new StringWriter(str.length()); unescapeJava(writer, str); return writer.toString(); } catch (IOException ioe) { // this should never ever happen while writing to a StringWriter throw new RuntimeException(ioe); } }
return escapeJavaStyleString(str, false, false);
/** * <p> * Unescapes any Java literals found in the <code>String</code>. For example, it will turn a sequence of * <code>'\'</code> and <code>'n'</code> into a newline character, unless the <code>'\'</code> is preceded by another * <code>'\'</code>. * </p> * * @param str the <code>String</code> to unescape, may be null * @return a new unescaped <code>String</code>, <code>null</code> if null string input */ public static String unescapeJava(String str) { if (str == null) { return null; } try { StringWriter writer = new StringWriter(str.length()); unescapeJava(writer, str); return writer.toString(); } catch (IOException ioe) { // this should never ever happen while writing to a StringWriter throw new RuntimeException(ioe); } }
/** * <p> * Worker method for the {@link #escapeJavaScript(String)} method. * </p> * * @param str String to escape values in, may be null * @param escapeSingleQuotes escapes single quotes if <code>true</code> * @param escapeForwardSlash TODO * @return the escaped string */ private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes, boolean escapeForwardSlash) { if (str == null) { return null; } try { StringWriter writer = new StringWriter(str.length() * 2); escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash); return writer.toString(); } catch (IOException ioe) { // this should never ever happen while writing to a StringWriter throw new RuntimeException(ioe); } }
/** * <p> * Worker method for the {@link #escapeJavaScript(String)} method. * </p> * * @param str String to escape values in, may be null * @param escapeSingleQuotes escapes single quotes if <code>true</code> * @param escapeForwardSlash TODO * @return the escaped string */ private static String escapeJavaStyleString(String str, boolean escapeSingleQuotes, boolean escapeForwardSlash) { if (str == null) { return null; } try { StringWriter writer = new StringWriter(str.length() * 2); escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash); return writer.toString(); } catch (IOException ioe) { // this should never ever happen while writing to a StringWriter throw new RuntimeException(ioe); } }