@Test public void testSnakeCaseFormat() { assertEquals(SnakeCase.format("Aa"), "aa"); assertEquals(SnakeCase.format("aA"), "a_a"); assertEquals(SnakeCase.format("_a__a_"), "a_a"); assertEquals(SnakeCase.format("RAM"), "ram"); assertEquals(SnakeCase.format("a7aAa"), "a7a_aa"); assertEquals(SnakeCase.format("A7AAa"), "a7a_aa"); }
public static String format(String input) { String subbed = new StringBuilder(input).reverse().toString().replaceAll("[^\\w]|_", " "); String reversedResult = Arrays.stream(REV_WORD_BOUND_PAT.split(subbed)) .map(String::trim) .map(String::toLowerCase) .filter(s -> s.length() > 0) .collect(Collectors.joining("_")); return new StringBuilder(reversedResult).reverse().toString(); }
SnakeCase { public static String format(String input) { String subbed = new StringBuilder(input).reverse().toString().replaceAll("[^\\w]|_", " "); String reversedResult = Arrays.stream(REV_WORD_BOUND_PAT.split(subbed)) .map(String::trim) .map(String::toLowerCase) .filter(s -> s.length() > 0) .collect(Collectors.joining("_")); return new StringBuilder(reversedResult).reverse().toString(); } }
SnakeCase { public static String format(String input) { String subbed = new StringBuilder(input).reverse().toString().replaceAll("[^\\w]|_", " "); String reversedResult = Arrays.stream(REV_WORD_BOUND_PAT.split(subbed)) .map(String::trim) .map(String::toLowerCase) .filter(s -> s.length() > 0) .collect(Collectors.joining("_")); return new StringBuilder(reversedResult).reverse().toString(); } private  SnakeCase(); }
SnakeCase { public static String format(String input) { String subbed = new StringBuilder(input).reverse().toString().replaceAll("[^\\w]|_", " "); String reversedResult = Arrays.stream(REV_WORD_BOUND_PAT.split(subbed)) .map(String::trim) .map(String::toLowerCase) .filter(s -> s.length() > 0) .collect(Collectors.joining("_")); return new StringBuilder(reversedResult).reverse().toString(); } private  SnakeCase(); static String format(String input); }
SnakeCase { public static String format(String input) { String subbed = new StringBuilder(input).reverse().toString().replaceAll("[^\\w]|_", " "); String reversedResult = Arrays.stream(REV_WORD_BOUND_PAT.split(subbed)) .map(String::trim) .map(String::toLowerCase) .filter(s -> s.length() > 0) .collect(Collectors.joining("_")); return new StringBuilder(reversedResult).reverse().toString(); } private  SnakeCase(); static String format(String input);  }