@Test public void toLowerCaseWithUnderscores() { assertNull(StringUtil.toLowerCaseWithUnderscores(null)); assertEquals("", StringUtil.toLowerCaseWithUnderscores("")); assertEquals("a", StringUtil.toLowerCaseWithUnderscores("A")); assertEquals("a", StringUtil.toLowerCaseWithUnderscores("a")); assertEquals("ab", StringUtil.toLowerCaseWithUnderscores("AB")); assertEquals("ab", StringUtil.toLowerCaseWithUnderscores("Ab")); assertEquals("a_b", StringUtil.toLowerCaseWithUnderscores("aB")); assertEquals("ab", StringUtil.toLowerCaseWithUnderscores("ab")); assertEquals("a_b", StringUtil.toLowerCaseWithUnderscores("A_B")); assertEquals("a_b", StringUtil.toLowerCaseWithUnderscores("A_b")); assertEquals("a_b", StringUtil.toLowerCaseWithUnderscores("a_B")); assertEquals("a_b", StringUtil.toLowerCaseWithUnderscores("a_b")); assertEquals("a_bc", StringUtil.toLowerCaseWithUnderscores("aBc")); assertEquals("a_bc_def", StringUtil.toLowerCaseWithUnderscores(" aBc def ")); assertEquals("a_bc_def", StringUtil.toLowerCaseWithUnderscores("aBcDef")); assertEquals("a_bc_def_ghi", StringUtil.toLowerCaseWithUnderscores("aBc def_ghi")); assertEquals("a_bc_def_ghi", StringUtil.toLowerCaseWithUnderscores("aBcDefGhi")); assertEquals("a_bc_def_ghi_123", StringUtil.toLowerCaseWithUnderscores("aBc def_ghi 123")); assertEquals("a_bc_def_ghi_123", StringUtil.toLowerCaseWithUnderscores("aBcDefGhi123")); assertEquals("a_bc_def_ghi_123", StringUtil.toLowerCaseWithUnderscores("aBcDEFGhi123")); assertEquals("123_a_bc_def_ghi", StringUtil.toLowerCaseWithUnderscores("123aBcDEFGhi")); assertEquals("__ab__", StringUtil.toLowerCaseWithUnderscores("__AB__")); assertEquals("__ab__", StringUtil.toLowerCaseWithUnderscores("__Ab__")); assertEquals("__a_b__", StringUtil.toLowerCaseWithUnderscores("__aB__")); assertEquals("__ab__", StringUtil.toLowerCaseWithUnderscores("__ab__")); assertEquals("__a__b__", StringUtil.toLowerCaseWithUnderscores("__A__B__")); assertEquals("__a__b__", StringUtil.toLowerCaseWithUnderscores("__A__b__")); assertEquals("__a__b__", StringUtil.toLowerCaseWithUnderscores("__a__B__")); assertEquals("__a__b__", StringUtil.toLowerCaseWithUnderscores("__a__b__")); assertEquals("..ab..", StringUtil.toLowerCaseWithUnderscores("..AB..")); assertEquals("..ab..", StringUtil.toLowerCaseWithUnderscores("..Ab..")); assertEquals("..a_b..", StringUtil.toLowerCaseWithUnderscores("..aB..")); assertEquals("..ab..", StringUtil.toLowerCaseWithUnderscores("..ab..")); assertEquals("..a..b..", StringUtil.toLowerCaseWithUnderscores("..A..B..")); assertEquals("..a..b..", StringUtil.toLowerCaseWithUnderscores("..A..b..")); assertEquals("..a..b..", StringUtil.toLowerCaseWithUnderscores("..a..B..")); assertEquals("..a..b..", StringUtil.toLowerCaseWithUnderscores("..a..b..")); assertEquals("..a..123_b..", StringUtil.toLowerCaseWithUnderscores("..A..123B..")); assertEquals("..a..123_b..", StringUtil.toLowerCaseWithUnderscores("..A..123b..")); assertEquals("..a..123_b..", StringUtil.toLowerCaseWithUnderscores("..a..123B..")); assertEquals("..a..123_b..", StringUtil.toLowerCaseWithUnderscores("..a..123b..")); assertEquals("_fmh.m._0.n", StringUtil.toLowerCaseWithUnderscores("_fmh.m._0.n")); assertEquals("aaa-bbb-ccc", StringUtil.toLowerCaseWithUnderscores("aaa-bbb-ccc")); }
public static String toLowerCaseWithUnderscores(String str) { return new WordTokenizer() { @Override protected void startSentence(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(Character.toLowerCase(ch)); } @Override protected void inWord(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startDigitSentence(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void startDigitWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(ch); } @Override protected void inDigitWord(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void inDelimiter(StringBuilder buffer, char ch) { buffer.append(ch); } }.parse(str); }
StringUtil { public static String toLowerCaseWithUnderscores(String str) { return new WordTokenizer() { @Override protected void startSentence(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(Character.toLowerCase(ch)); } @Override protected void inWord(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startDigitSentence(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void startDigitWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(ch); } @Override protected void inDigitWord(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void inDelimiter(StringBuilder buffer, char ch) { buffer.append(ch); } }.parse(str); } }
StringUtil { public static String toLowerCaseWithUnderscores(String str) { return new WordTokenizer() { @Override protected void startSentence(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(Character.toLowerCase(ch)); } @Override protected void inWord(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startDigitSentence(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void startDigitWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(ch); } @Override protected void inDigitWord(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void inDelimiter(StringBuilder buffer, char ch) { buffer.append(ch); } }.parse(str); }  }
StringUtil { public static String toLowerCaseWithUnderscores(String str) { return new WordTokenizer() { @Override protected void startSentence(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(Character.toLowerCase(ch)); } @Override protected void inWord(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startDigitSentence(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void startDigitWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(ch); } @Override protected void inDigitWord(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void inDelimiter(StringBuilder buffer, char ch) { buffer.append(ch); } }.parse(str); }  static boolean isEmpty(String str); static boolean isAllEmpty(String...strings); static boolean isAnyEmpty(String...strings); static boolean isNotEmpty(String str); static boolean isBlank(String str); static boolean isAllBlank(String...strings); static boolean isAnyBlank(String...strings); static boolean isNotBlank(String str); static String defaultIfNull(String str); static String defaultIfNull(String str, String defaultStr); static String defaultIfEmpty(String str); static String defaultIfEmpty(String str, String defaultStr); static String defaultIfBlank(String str); static String defaultIfBlank(String str, String defaultStr); static String trim(String str); static void trimAll(String[] strings); static String trim(String str, String stripChars); static String trimStart(String str); static String trimStart(String str, String stripChars); static String trimEnd(String str); static String trimEnd(String str, String stripChars); static String trimToNull(String str); static String trimToNull(String str, String stripChars); static String trimToEmpty(String str); static String trimToEmpty(String str, String stripChars); static boolean equals(String str1, String str2); static boolean equalsIgnoreCase(String str1, String str2); static int equalsOne(String src, String[] dest); static int equalsOneIgnoreCase(String src, String[] dest); static boolean equalsIgnoreCase(String as[], String as1[]); static boolean isAlpha(String str); static boolean isAlphaSpace(String str); static boolean isAlphanumeric(String str); static boolean isAlphanumericSpace(String str); static boolean isNumeric(String str); static boolean isNumericSpace(String str); static boolean isWhitespace(String str); static String toUpperCase(String str); static String toLowerCase(String str); static String capitalize(String str); static String uncapitalize(String str); static String decapitalize(String str); static String swapCase(String str); static String fromCamelCase(String str, char separator); static String[] split(String str); static List<Long> parseStringToLongList(String source, String token); static String[] splitNoCompress(String src, String delimiter); static String[] splitc(String src, String d); static String[] splitc(String src, char delimiter); static String[] splitc(String src, char[] delimiters); static String[] split(String str, char separatorChar); static String[] split(String str, String separatorChars); static String[] split(String str, String separatorChars, int max); static String join(T...array); static String join(T[] array, char separator); static String join(T[] array, String separator); static String join(Iterator<?> iterator, char separator); static String join(Iterator<?> iterator, String separator); static int indexOf(String str, char searchChar); static int indexOf(String str, char searchChar, int startPos); static int indexOf(String str, String searchStr); static int indexOf(String str, String searchStr, int startPos); static int indexOf(int num, String str, String searchStr); static int indexOfAny(String str, char[] searchChars); static int indexOfAny(String str, char[] searchChars, int startIndex); static int indexOfAny(String str, String searchChars); static int indexOfAny(String str, String searchChars, int startIndex); static int indexOfAny(String str, String[] searchStrs); static int indexOfAny(String str, String[] searchStrs, int startIndex); static int indexOfAnyBut(String str, char[] searchChars); static int indexOfAnyBut(String str, String searchChars); static int lastIndexOf(String str, char searchChar); static int lastIndexOf(String str, char searchChar, int startPos); static int lastIndexOf(String str, String searchStr); static int lastIndexOf(String str, String searchStr, int startPos); static int lastIndexOfAny(String str, String[] searchStrs); static boolean contains(String str, char searchChar); static boolean contains(String str, String searchStr); static boolean containsOnly(String str, char[] valid); static boolean containsOnly(String str, String valid); static boolean containsNone(String str, char[] invalid); static boolean containsNone(String str, String invalidChars); static int countMatches(String str, String subStr); static String substring(String str, int start); static String substring(String str, int start, int end); static String left(String str, int len); static String right(String str, int len); static String mid(String str, int pos, int len); static String substringBefore(String str, String separator); static String substringAfter(String str, String separator); static String substringBeforeLast(String str, String separator); static String substringAfterLast(String str, String separator); static String substringBetween(String str, String tag); static String substringBetween(String str, String open, String close); static String substringBetween(String str, String open, String close, int fromIndex); static String deleteWhitespace(String str); static String replaceOnce(String text, String repl, String with); static String replaceOnce(String str, char searchChar, char replaceChar); static String replace(String text, String repl, String with); static String replace(String text, String repl, String with, int max); static String replaceOnce(int startPos, String text, String repl, String with); static String replaceChars(String str, char searchChar, char replaceChar); static String replaceChars(String s, char[] sub, char[] with); static String replaceChars(String str, String searchChars, String replaceChars); static String replaceLast(String text, String sub, String with); static String replaceLast(String text, char sub, char with); static String overlay(String str, String overlay, int start, int end); static String chomp(String str); static String chomp(String str, String separator); static String chop(String str); static String repeat(String str, int repeat); static String repeat(char c, int count); static String alignLeft(String str, int size); static String alignLeft(String str, int size, char padChar); static String alignLeft(String str, int size, String padStr); static String alignRight(String str, int size); static String alignRight(String str, int size, char padChar); static String alignRight(String str, int size, String padStr); static String center(String str, int size); static String center(String str, int size, char padChar); static String center(String str, int size, String padStr); static String reverse(String str); static String reverseDelimited(String str, char separatorChar); static String reverseDelimited(String str, String separatorChars, String separator); static String abbreviate(String str, int maxWidth); static String abbreviate(String str, int offset, int maxWidth); static String difference(String str1, String str2); static int indexOfDifference(String str1, String str2); static int getLevenshteinDistance(String s, String t); static String STAM(String str, String wadChar, int length); static String toUpperCase4First(String str); static String toLowerCase4First(String str); static String getASCII(String str); static String toCamelCase(String str); static String toPascalCase(String str); static String toUpperCaseWithUnderscores(String str); static String toLowerCaseWithUnderscores(String str); static String longToString(long longValue); static String longToString(long longValue, boolean noCase); static String bytesToString(byte[] bytes); static String bytesToString(byte[] bytes, boolean noCase); static boolean endsWithChar(String str, char ch); static boolean startsWithChar(String str, char ch); static int indexOfChars(String string, String chars); static int indexOfChars(String string, String chars, int startindex); static int indexOfChars(String string, char[] chars); static int indexOfChars(String string, char[] chars, int startindex); static String toString(Object value); static String toString(Collection<String> collection); static String toString(Collection<String> collection, String split); static boolean isDigits(String string); static boolean endsWithIgnoreCase(String str, String suffix); }
StringUtil { public static String toLowerCaseWithUnderscores(String str) { return new WordTokenizer() { @Override protected void startSentence(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(Character.toLowerCase(ch)); } @Override protected void inWord(StringBuilder buffer, char ch) { buffer.append(Character.toLowerCase(ch)); } @Override protected void startDigitSentence(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void startDigitWord(StringBuilder buffer, char ch) { if (!isDelimiter(buffer.charAt(buffer.length() - 1))) { buffer.append(UNDERSCORE); } buffer.append(ch); } @Override protected void inDigitWord(StringBuilder buffer, char ch) { buffer.append(ch); } @Override protected void inDelimiter(StringBuilder buffer, char ch) { buffer.append(ch); } }.parse(str); }  static boolean isEmpty(String str); static boolean isAllEmpty(String...strings); static boolean isAnyEmpty(String...strings); static boolean isNotEmpty(String str); static boolean isBlank(String str); static boolean isAllBlank(String...strings); static boolean isAnyBlank(String...strings); static boolean isNotBlank(String str); static String defaultIfNull(String str); static String defaultIfNull(String str, String defaultStr); static String defaultIfEmpty(String str); static String defaultIfEmpty(String str, String defaultStr); static String defaultIfBlank(String str); static String defaultIfBlank(String str, String defaultStr); static String trim(String str); static void trimAll(String[] strings); static String trim(String str, String stripChars); static String trimStart(String str); static String trimStart(String str, String stripChars); static String trimEnd(String str); static String trimEnd(String str, String stripChars); static String trimToNull(String str); static String trimToNull(String str, String stripChars); static String trimToEmpty(String str); static String trimToEmpty(String str, String stripChars); static boolean equals(String str1, String str2); static boolean equalsIgnoreCase(String str1, String str2); static int equalsOne(String src, String[] dest); static int equalsOneIgnoreCase(String src, String[] dest); static boolean equalsIgnoreCase(String as[], String as1[]); static boolean isAlpha(String str); static boolean isAlphaSpace(String str); static boolean isAlphanumeric(String str); static boolean isAlphanumericSpace(String str); static boolean isNumeric(String str); static boolean isNumericSpace(String str); static boolean isWhitespace(String str); static String toUpperCase(String str); static String toLowerCase(String str); static String capitalize(String str); static String uncapitalize(String str); static String decapitalize(String str); static String swapCase(String str); static String fromCamelCase(String str, char separator); static String[] split(String str); static List<Long> parseStringToLongList(String source, String token); static String[] splitNoCompress(String src, String delimiter); static String[] splitc(String src, String d); static String[] splitc(String src, char delimiter); static String[] splitc(String src, char[] delimiters); static String[] split(String str, char separatorChar); static String[] split(String str, String separatorChars); static String[] split(String str, String separatorChars, int max); static String join(T...array); static String join(T[] array, char separator); static String join(T[] array, String separator); static String join(Iterator<?> iterator, char separator); static String join(Iterator<?> iterator, String separator); static int indexOf(String str, char searchChar); static int indexOf(String str, char searchChar, int startPos); static int indexOf(String str, String searchStr); static int indexOf(String str, String searchStr, int startPos); static int indexOf(int num, String str, String searchStr); static int indexOfAny(String str, char[] searchChars); static int indexOfAny(String str, char[] searchChars, int startIndex); static int indexOfAny(String str, String searchChars); static int indexOfAny(String str, String searchChars, int startIndex); static int indexOfAny(String str, String[] searchStrs); static int indexOfAny(String str, String[] searchStrs, int startIndex); static int indexOfAnyBut(String str, char[] searchChars); static int indexOfAnyBut(String str, String searchChars); static int lastIndexOf(String str, char searchChar); static int lastIndexOf(String str, char searchChar, int startPos); static int lastIndexOf(String str, String searchStr); static int lastIndexOf(String str, String searchStr, int startPos); static int lastIndexOfAny(String str, String[] searchStrs); static boolean contains(String str, char searchChar); static boolean contains(String str, String searchStr); static boolean containsOnly(String str, char[] valid); static boolean containsOnly(String str, String valid); static boolean containsNone(String str, char[] invalid); static boolean containsNone(String str, String invalidChars); static int countMatches(String str, String subStr); static String substring(String str, int start); static String substring(String str, int start, int end); static String left(String str, int len); static String right(String str, int len); static String mid(String str, int pos, int len); static String substringBefore(String str, String separator); static String substringAfter(String str, String separator); static String substringBeforeLast(String str, String separator); static String substringAfterLast(String str, String separator); static String substringBetween(String str, String tag); static String substringBetween(String str, String open, String close); static String substringBetween(String str, String open, String close, int fromIndex); static String deleteWhitespace(String str); static String replaceOnce(String text, String repl, String with); static String replaceOnce(String str, char searchChar, char replaceChar); static String replace(String text, String repl, String with); static String replace(String text, String repl, String with, int max); static String replaceOnce(int startPos, String text, String repl, String with); static String replaceChars(String str, char searchChar, char replaceChar); static String replaceChars(String s, char[] sub, char[] with); static String replaceChars(String str, String searchChars, String replaceChars); static String replaceLast(String text, String sub, String with); static String replaceLast(String text, char sub, char with); static String overlay(String str, String overlay, int start, int end); static String chomp(String str); static String chomp(String str, String separator); static String chop(String str); static String repeat(String str, int repeat); static String repeat(char c, int count); static String alignLeft(String str, int size); static String alignLeft(String str, int size, char padChar); static String alignLeft(String str, int size, String padStr); static String alignRight(String str, int size); static String alignRight(String str, int size, char padChar); static String alignRight(String str, int size, String padStr); static String center(String str, int size); static String center(String str, int size, char padChar); static String center(String str, int size, String padStr); static String reverse(String str); static String reverseDelimited(String str, char separatorChar); static String reverseDelimited(String str, String separatorChars, String separator); static String abbreviate(String str, int maxWidth); static String abbreviate(String str, int offset, int maxWidth); static String difference(String str1, String str2); static int indexOfDifference(String str1, String str2); static int getLevenshteinDistance(String s, String t); static String STAM(String str, String wadChar, int length); static String toUpperCase4First(String str); static String toLowerCase4First(String str); static String getASCII(String str); static String toCamelCase(String str); static String toPascalCase(String str); static String toUpperCaseWithUnderscores(String str); static String toLowerCaseWithUnderscores(String str); static String longToString(long longValue); static String longToString(long longValue, boolean noCase); static String bytesToString(byte[] bytes); static String bytesToString(byte[] bytes, boolean noCase); static boolean endsWithChar(String str, char ch); static boolean startsWithChar(String str, char ch); static int indexOfChars(String string, String chars); static int indexOfChars(String string, String chars, int startindex); static int indexOfChars(String string, char[] chars); static int indexOfChars(String string, char[] chars, int startindex); static String toString(Object value); static String toString(Collection<String> collection); static String toString(Collection<String> collection, String split); static boolean isDigits(String string); static boolean endsWithIgnoreCase(String str, String suffix);  }