@Test public void quoteJavaStringTest () { Assert.assertEquals ("\"abc\"", StringUtils.quoteJavaString ("abc")); Assert.assertEquals ("\"ab\\\"c\"", StringUtils.quoteJavaString ("ab\"c")); Assert.assertEquals ("\"\\\"abc\\\"\"", StringUtils.quoteJavaString ("\"abc\"")); }
public static String quoteJavaString (String str) { StringBuilder builder = new StringBuilder (); builder.append ('"'); int index = 0; int fromIndex = 0; while ((index = str.indexOf ('"', fromIndex)) >= 0) { if (index == fromIndex) { builder.append ("\\\""); ++fromIndex; continue; } builder.append (str.substring (fromIndex, index)); builder.append ("\\\""); fromIndex = index + 1; } if (fromIndex < str.length ()) builder.append (str.substring (fromIndex)); builder.append ('"'); return builder.toString (); }
StringUtils { public static String quoteJavaString (String str) { StringBuilder builder = new StringBuilder (); builder.append ('"'); int index = 0; int fromIndex = 0; while ((index = str.indexOf ('"', fromIndex)) >= 0) { if (index == fromIndex) { builder.append ("\\\""); ++fromIndex; continue; } builder.append (str.substring (fromIndex, index)); builder.append ("\\\""); fromIndex = index + 1; } if (fromIndex < str.length ()) builder.append (str.substring (fromIndex)); builder.append ('"'); return builder.toString (); } }
StringUtils { public static String quoteJavaString (String str) { StringBuilder builder = new StringBuilder (); builder.append ('"'); int index = 0; int fromIndex = 0; while ((index = str.indexOf ('"', fromIndex)) >= 0) { if (index == fromIndex) { builder.append ("\\\""); ++fromIndex; continue; } builder.append (str.substring (fromIndex, index)); builder.append ("\\\""); fromIndex = index + 1; } if (fromIndex < str.length ()) builder.append (str.substring (fromIndex)); builder.append ('"'); return builder.toString (); }  }
StringUtils { public static String quoteJavaString (String str) { StringBuilder builder = new StringBuilder (); builder.append ('"'); int index = 0; int fromIndex = 0; while ((index = str.indexOf ('"', fromIndex)) >= 0) { if (index == fromIndex) { builder.append ("\\\""); ++fromIndex; continue; } builder.append (str.substring (fromIndex, index)); builder.append ("\\\""); fromIndex = index + 1; } if (fromIndex < str.length ()) builder.append (str.substring (fromIndex)); builder.append ('"'); return builder.toString (); }  static String getHexString(byte[] bytes); static String getHexString(byte[] bytes, int start, int end); static byte[] getBytesFromHexString(String str); static String repeat(char c, int n); static void printRepeat(PrintWriter pw, char c, int width); static void print(PrintWriter pw, String s, int width, boolean leftAlign, boolean pad); static String getStringFromStream(InputStream is); static String getStringFromReader(Reader reader); static String[] shiftArgs(String[] args); static String[] shiftArgs(String[] args, int num); static String trimEnd(String str); static String quoteJavaString(String str); static String eval(String str, JaqyInterpreter interpreter); static boolean getOnOffState(String state, String field); static String stripQuote(String str, char quoteChar); static String[] parseArgs(CommandArgumentType argType, String arguments, JaqyInterpreter interpreter); }
StringUtils { public static String quoteJavaString (String str) { StringBuilder builder = new StringBuilder (); builder.append ('"'); int index = 0; int fromIndex = 0; while ((index = str.indexOf ('"', fromIndex)) >= 0) { if (index == fromIndex) { builder.append ("\\\""); ++fromIndex; continue; } builder.append (str.substring (fromIndex, index)); builder.append ("\\\""); fromIndex = index + 1; } if (fromIndex < str.length ()) builder.append (str.substring (fromIndex)); builder.append ('"'); return builder.toString (); }  static String getHexString(byte[] bytes); static String getHexString(byte[] bytes, int start, int end); static byte[] getBytesFromHexString(String str); static String repeat(char c, int n); static void printRepeat(PrintWriter pw, char c, int width); static void print(PrintWriter pw, String s, int width, boolean leftAlign, boolean pad); static String getStringFromStream(InputStream is); static String getStringFromReader(Reader reader); static String[] shiftArgs(String[] args); static String[] shiftArgs(String[] args, int num); static String trimEnd(String str); static String quoteJavaString(String str); static String eval(String str, JaqyInterpreter interpreter); static boolean getOnOffState(String state, String field); static String stripQuote(String str, char quoteChar); static String[] parseArgs(CommandArgumentType argType, String arguments, JaqyInterpreter interpreter);  }