@Test public void testEscapeValueForLike() { assertEquals("", FilterUtil.escapeValueForLike("")); assertEquals("abc", FilterUtil.escapeValueForLike("abc")); assertEquals("\\%abc", FilterUtil.escapeValueForLike("%abc")); assertEquals("a\\%bc", FilterUtil.escapeValueForLike("a%bc")); assertEquals("abc\\%", FilterUtil.escapeValueForLike("abc%")); assertEquals("\\_abc", FilterUtil.escapeValueForLike("_abc")); assertEquals("a\\_bc", FilterUtil.escapeValueForLike("a_bc")); assertEquals("abc\\_", FilterUtil.escapeValueForLike("abc_")); assertEquals("a\\_b\\%c", FilterUtil.escapeValueForLike("a_b%c")); assertEquals("abc\\%\\%", FilterUtil.escapeValueForLike("abc%%")); assertEquals("\\%\\%\\_\\_abc", FilterUtil.escapeValueForLike("%%__abc")); }
public static String escapeValueForLike(String value) { if (!value.contains(undescoreStr) && !value.contains(percentStr)) { return value; } int len = value.length(); StringBuilder out = new StringBuilder(len * 2); for (int i = 0; i < len; i++) { char c = value.charAt(i); if (c == undescore || c == percent) { out.append('\\'); } out.append(c); } return out.toString(); }
FilterUtil { public static String escapeValueForLike(String value) { if (!value.contains(undescoreStr) && !value.contains(percentStr)) { return value; } int len = value.length(); StringBuilder out = new StringBuilder(len * 2); for (int i = 0; i < len; i++) { char c = value.charAt(i); if (c == undescore || c == percent) { out.append('\\'); } out.append(c); } return out.toString(); } }
FilterUtil { public static String escapeValueForLike(String value) { if (!value.contains(undescoreStr) && !value.contains(percentStr)) { return value; } int len = value.length(); StringBuilder out = new StringBuilder(len * 2); for (int i = 0; i < len; i++) { char c = value.charAt(i); if (c == undescore || c == percent) { out.append('\\'); } out.append(c); } return out.toString(); }  }
FilterUtil { public static String escapeValueForLike(String value) { if (!value.contains(undescoreStr) && !value.contains(percentStr)) { return value; } int len = value.length(); StringBuilder out = new StringBuilder(len * 2); for (int i = 0; i < len; i++) { char c = value.charAt(i); if (c == undescore || c == percent) { out.append('\\'); } out.append(c); } return out.toString(); }  static String escapeValueForLike(String value); }
FilterUtil { public static String escapeValueForLike(String value) { if (!value.contains(undescoreStr) && !value.contains(percentStr)) { return value; } int len = value.length(); StringBuilder out = new StringBuilder(len * 2); for (int i = 0; i < len; i++) { char c = value.charAt(i); if (c == undescore || c == percent) { out.append('\\'); } out.append(c); } return out.toString(); }  static String escapeValueForLike(String value);  }