StringUtils { public static int unescapedIndexOf(String str, int startIndex, char toFind) { if (toFind == '\\') { throw new IllegalArgumentException("Cannot look for the escape character."); } int i = startIndex; while (i < str.length()) { char ch = str.charAt(i); if (ch == toFind) { return i; } if (ch == '\\') i += 2; else i++; } return -1; } private  StringUtils(); static String byteArrayToHex(byte[] array); static void appendHexFixedLength(char ch, StringBuilder result); static String emptyForNull(String str); static String stripSeperatorsFromEnd(String str); static String[] splitText(String text, String delimiters); static String[] splitLines(String text); static List<String> toLines(String output); static String[] splitBySpaces(String text); static String getTopMostClassName(String className); static String getResourceAsString(String resourcePath, Charset encoding); static String getOsLineSeparator(); static String replaceLFWithPreferredLineSeparator(String str); static String replaceLFWithPreferredLineSeparator(String str, Project ownerProject); static void writeStringToFile(String content, Charset encoding, Path file); static void writeStringToFile(String content, Charset encoding, File file); static int unescapedIndexOf(String str, int startIndex, char toFind); static String unescapeString(String str); static String[] unescapedSplit(String str, char splitChar); static String[] unescapedSplit(String str, char splitChar, int maxSplitCount); static String capitalizeFirstCharacter(String str); static List<String> splitArgs(String cmdLine); static final Collator STR_CMP; static final Charset UTF8; }
@Test public void testUnescapedIndexOfWithoutEscapeChar() { assertEquals(0, StringUtils.unescapedIndexOf(":", 0, ':')); assertEquals(0, StringUtils.unescapedIndexOf(":hello", 0, ':')); assertEquals(0, StringUtils.unescapedIndexOf(":he:llo", 0, ':')); assertEquals(5, StringUtils.unescapedIndexOf("hello:", 0, ':')); assertEquals(3, StringUtils.unescapedIndexOf(":he:llo", 1, ':')); }
@Test public void testUnescapedIndexOfSkipsEscaped1() { assertEquals(8, StringUtils.unescapedIndexOf("0123\\:67:9", 0, ':')); }
@Test public void testUnescapedIndexOfSkipsEscaped2() { assertEquals(10, StringUtils.unescapedIndexOf("0123\\\\\\:89:X", 0, ':')); }
@Test public void testUnescapedIndexOfEscapedSlashBeforeMatch() { assertEquals(6, StringUtils.unescapedIndexOf("0123\\\\:78", 0, ':')); }
@Test public void testUnescapedIndexOfNotFound() { assertEquals(-1, StringUtils.unescapedIndexOf("012378", 0, ':')); assertEquals(-1, StringUtils.unescapedIndexOf("", 0, ':')); }