@Test public void testEscape() throws Exception { assertEquals("\\n\\t\\n\\t", Util.escape("\n\t\n\t")); assertEquals("\\\\\\\\", Util.escape("\\\\")); }
public static String escape(String s) { StringBuilder buff = new StringBuilder(s.length() + 20); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch(c) { case '\r': if (i == s.length() - 1 || s.charAt(i + 1) != '\n') { buff.append("\\n"); } break; case '\n': buff.append("\\n"); break; case '\t': buff.append("\\t"); break; case '\\': buff.append("\\\\"); break; default: buff.append(c); } } return buff.toString(); }
Util { public static String escape(String s) { StringBuilder buff = new StringBuilder(s.length() + 20); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch(c) { case '\r': if (i == s.length() - 1 || s.charAt(i + 1) != '\n') { buff.append("\\n"); } break; case '\n': buff.append("\\n"); break; case '\t': buff.append("\\t"); break; case '\\': buff.append("\\\\"); break; default: buff.append(c); } } return buff.toString(); } }
Util { public static String escape(String s) { StringBuilder buff = new StringBuilder(s.length() + 20); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch(c) { case '\r': if (i == s.length() - 1 || s.charAt(i + 1) != '\n') { buff.append("\\n"); } break; case '\n': buff.append("\\n"); break; case '\t': buff.append("\\t"); break; case '\\': buff.append("\\\\"); break; default: buff.append(c); } } return buff.toString(); } private  Util(); }
Util { public static String escape(String s) { StringBuilder buff = new StringBuilder(s.length() + 20); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch(c) { case '\r': if (i == s.length() - 1 || s.charAt(i + 1) != '\n') { buff.append("\\n"); } break; case '\n': buff.append("\\n"); break; case '\t': buff.append("\\t"); break; case '\\': buff.append("\\\\"); break; default: buff.append(c); } } return buff.toString(); } private  Util(); static String logLevelNameForValue(int value); static void formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer); static void formatTimeISO(long time, StringBuilder sbuffer); static String escape(String s); }
Util { public static String escape(String s) { StringBuilder buff = new StringBuilder(s.length() + 20); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch(c) { case '\r': if (i == s.length() - 1 || s.charAt(i + 1) != '\n') { buff.append("\\n"); } break; case '\n': buff.append("\\n"); break; case '\t': buff.append("\\t"); break; case '\\': buff.append("\\\\"); break; default: buff.append(c); } } return buff.toString(); } private  Util(); static String logLevelNameForValue(int value); static void formatTimeSecondsSinceEpoch(final long time, StringBuilder sbuffer); static void formatTimeISO(long time, StringBuilder sbuffer); static String escape(String s);  }