@Test public void toSnake() { assertEquals("", Strings.toSnake("")); assertEquals("A_B", Strings.toSnake("aB")); assertEquals("AB", Strings.toSnake("AB")); assertEquals("AB", Strings.toSnake("Ab")); assertEquals("ABC", Strings.toSnake("abc")); assertEquals("ABC", Strings.toSnake("Abc")); assertEquals("A_BC", Strings.toSnake("ABc")); assertEquals("ABC", Strings.toSnake("ABC")); assertEquals("A_BC", Strings.toSnake("aBc")); assertEquals("A_BC", Strings.toSnake("aBC")); assertEquals("AB_C", Strings.toSnake("abC")); assertEquals("AB_CD", Strings.toSnake("abCd")); assertEquals("AB_CD", Strings.toSnake("ABCd")); assertEquals("AB_CD", Strings.toSnake("abCD")); assertEquals("AB_CD", Strings.toSnake("AbCd")); assertEquals("0B", Strings.toSnake("0b")); assertEquals("0_B", Strings.toSnake("0B")); assertEquals("A1", Strings.toSnake("a1")); assertEquals("A1", Strings.toSnake("A1")); }
public static String toSnake(String camel) { if (Strings.isBlank(camel)) return ""; ArrayList<String> words = new ArrayList<String>(); Matcher matcher = SNAKE_CASE_WORD.matcher(camel); while(matcher.find()) { MatchResult result = matcher.toMatchResult(); String word = camel.substring(result.start(), result.end()); words.add(word.toUpperCase()); } return Strings.joinBy("_", words); }
Strings { public static String toSnake(String camel) { if (Strings.isBlank(camel)) return ""; ArrayList<String> words = new ArrayList<String>(); Matcher matcher = SNAKE_CASE_WORD.matcher(camel); while(matcher.find()) { MatchResult result = matcher.toMatchResult(); String word = camel.substring(result.start(), result.end()); words.add(word.toUpperCase()); } return Strings.joinBy("_", words); } }
Strings { public static String toSnake(String camel) { if (Strings.isBlank(camel)) return ""; ArrayList<String> words = new ArrayList<String>(); Matcher matcher = SNAKE_CASE_WORD.matcher(camel); while(matcher.find()) { MatchResult result = matcher.toMatchResult(); String word = camel.substring(result.start(), result.end()); words.add(word.toUpperCase()); } return Strings.joinBy("_", words); } private  Strings(); }
Strings { public static String toSnake(String camel) { if (Strings.isBlank(camel)) return ""; ArrayList<String> words = new ArrayList<String>(); Matcher matcher = SNAKE_CASE_WORD.matcher(camel); while(matcher.find()) { MatchResult result = matcher.toMatchResult(); String word = camel.substring(result.start(), result.end()); words.add(word.toUpperCase()); } return Strings.joinBy("_", words); } private  Strings(); static String substitute(String string, Map<String, ? extends Object> replace); static String substitute(String string, Map<String, ? extends Object> replace, Locale locale); static String findPlaceHolder(String string); static String clearEscapedPlaceHolder(String dirty); static T proper(T returnIfNotEmpty, T alternative); static String toCamel(String snake); static String toSnake(String camel); static String join(T... joinees); static String joinBy(String separator, T... joinees); static String join(List<T> joinees); static String joinBy(String separator, List<T> joinees); static boolean isBlank(CharSequence suspect); static boolean containBlank(CharSequence suspect); static String removeBlanks(CharSequence target); static boolean isEmpty(CharSequence suspect); static boolean isEmpty(CharSequence suspect, boolean removeBlanks); static String reverse(String reversee); static String trim(String target); static String[] split(String regex, String target); static boolean equalsIgnoreCase(String source, String destination); static boolean startsWith(String text, String prefix); static boolean startsWith(String text, String prefix, boolean textCompare); static boolean endsWith(String text, String prefix); static boolean endsWith(String text, String prefix, boolean textCompare); static String escapeHTML(CharSequence html); static String escapeRegex(CharSequence text); }
Strings { public static String toSnake(String camel) { if (Strings.isBlank(camel)) return ""; ArrayList<String> words = new ArrayList<String>(); Matcher matcher = SNAKE_CASE_WORD.matcher(camel); while(matcher.find()) { MatchResult result = matcher.toMatchResult(); String word = camel.substring(result.start(), result.end()); words.add(word.toUpperCase()); } return Strings.joinBy("_", words); } private  Strings(); static String substitute(String string, Map<String, ? extends Object> replace); static String substitute(String string, Map<String, ? extends Object> replace, Locale locale); static String findPlaceHolder(String string); static String clearEscapedPlaceHolder(String dirty); static T proper(T returnIfNotEmpty, T alternative); static String toCamel(String snake); static String toSnake(String camel); static String join(T... joinees); static String joinBy(String separator, T... joinees); static String join(List<T> joinees); static String joinBy(String separator, List<T> joinees); static boolean isBlank(CharSequence suspect); static boolean containBlank(CharSequence suspect); static String removeBlanks(CharSequence target); static boolean isEmpty(CharSequence suspect); static boolean isEmpty(CharSequence suspect, boolean removeBlanks); static String reverse(String reversee); static String trim(String target); static String[] split(String regex, String target); static boolean equalsIgnoreCase(String source, String destination); static boolean startsWith(String text, String prefix); static boolean startsWith(String text, String prefix, boolean textCompare); static boolean endsWith(String text, String prefix); static boolean endsWith(String text, String prefix, boolean textCompare); static String escapeHTML(CharSequence html); static String escapeRegex(CharSequence text);  }