StringUtil { public static int columnNumberAt(CharSequence charSeq, final int offsetInclusive) { if (offsetInclusive == charSeq.length()) { return charSeq.length() == 0 ? 1 : 1 + columnNumberAt(charSeq, offsetInclusive - 1); } else if (offsetInclusive > charSeq.length() || offsetInclusive < 0) { return -1; } int col = 0; char next = 0; for (int i = offsetInclusive; i >= 0; i--) { char c = charSeq.charAt(i); if (offsetInclusive != i) { if (c == '\n' || c == '\r' && next != '\n') { return col; } } col++; next = c; } return col; } private  StringUtil(); static int lineNumberAt(CharSequence charSeq, int offsetInclusive); static int columnNumberAt(CharSequence charSeq, final int offsetInclusive); static String percentageString(double val, int numDecimals); @Deprecated static boolean startsWithAny(String text, String... prefixes); static boolean isAnyOf(String text, String... tests); static String withoutPrefixes(String text, String... prefixes); @Deprecated static boolean isNotEmpty(String value); @Deprecated static boolean isEmpty(String value); @Deprecated static boolean isMissing(String value); @Deprecated static boolean areSemanticEquals(String a, String b); @Deprecated static String replaceString(final String original, final String oldString, final String newString); @Deprecated static void appendXmlEscaped(StringBuilder buf, String src, boolean supportUTF8); static String removedInvalidXml10Characters(String text); static String escapeWhitespace(Object o); @Deprecated static String replaceString(final String original, char oldChar, final String newString); @Deprecated static String[] substringsOf(String source, char delimiter); @Deprecated static String[] substringsOf(String str, String separator); @Deprecated static void asStringOn(StringBuffer sb, Iterator<?> iter, String separator); @Deprecated static void asStringOn(StringBuilder sb, Object[] items, String separator); static int maxCommonLeadingWhitespaceForAll(String[] strings); static int lengthOfShortestIn(String[] strings); static String[] trimStartOn(String[] strings, int trimDepth); @Deprecated static String lpad(String s, int length); static boolean isSame(String s1, String s2, boolean trim, boolean ignoreCase,
                                 boolean standardizeWhitespace); static String asString(Object[] items, String separator); static String[] getEmptyStrings(); static String toCamelCase(String name); static String toCamelCase(String name, boolean forceLowerCase); static String escapeJava(String str);  }
@Test public void testColumnNumber() { assertEquals(-1, StringUtil.columnNumberAt("f\rah\nb", -1)); assertEquals(1, StringUtil.columnNumberAt("f\rah\nb", 0)); assertEquals(2, StringUtil.columnNumberAt("f\rah\nb", 1)); assertEquals(1, StringUtil.columnNumberAt("f\rah\nb", 2)); assertEquals(2, StringUtil.columnNumberAt("f\rah\nb", 3)); assertEquals(3, StringUtil.columnNumberAt("f\rah\nb", 4)); assertEquals(1, StringUtil.columnNumberAt("f\rah\nb", 5)); assertEquals(2, StringUtil.columnNumberAt("f\rah\nb", 6)); assertEquals(-1, StringUtil.columnNumberAt("f\rah\nb", 7)); }
@Test public void testColumnNumberCrLf() { assertEquals(-1, StringUtil.columnNumberAt("f\r\nb", -1)); assertEquals(1, StringUtil.columnNumberAt("f\r\nb", 0)); assertEquals(2, StringUtil.columnNumberAt("f\r\nb", 1)); assertEquals(3, StringUtil.columnNumberAt("f\r\nb", 2)); assertEquals(1, StringUtil.columnNumberAt("f\r\nb", 3)); assertEquals(2, StringUtil.columnNumberAt("f\r\nb", 4)); assertEquals(-1, StringUtil.columnNumberAt("f\r\nb", 5)); }
@Test public void testColumnNumberTrailing() { assertEquals(1, StringUtil.columnNumberAt("\n", 0)); assertEquals(2, StringUtil.columnNumberAt("\n", 1)); assertEquals(-1, StringUtil.columnNumberAt("\n", 2)); }
@Test public void testColumnNumberEmpty() { assertEquals(1, StringUtil.columnNumberAt("", 0)); assertEquals(-1, StringUtil.columnNumberAt("", 1)); }