@Test @DisplayName("snake converts a normal non-empty string containing no upper case") void snakeConvertsNo_() { assertEquals("THIS_IS_TO_BE_SNAKED", snake("ThisIsToBeSnaked")); }
public static String snake(String s) { if (s == null) { return null; } int dst = 0; final var result = new char[2 * s.length()]; for (int src = 0; src < s.length(); src++) { if (Character.isUpperCase(s.charAt(src)) && src > 0) { result[dst++] = '_'; } result[dst++] = Character.toUpperCase(s.charAt(src)); } return new String(result, 0, dst); }
CaseTools { public static String snake(String s) { if (s == null) { return null; } int dst = 0; final var result = new char[2 * s.length()]; for (int src = 0; src < s.length(); src++) { if (Character.isUpperCase(s.charAt(src)) && src > 0) { result[dst++] = '_'; } result[dst++] = Character.toUpperCase(s.charAt(src)); } return new String(result, 0, dst); } }
CaseTools { public static String snake(String s) { if (s == null) { return null; } int dst = 0; final var result = new char[2 * s.length()]; for (int src = 0; src < s.length(); src++) { if (Character.isUpperCase(s.charAt(src)) && src > 0) { result[dst++] = '_'; } result[dst++] = Character.toUpperCase(s.charAt(src)); } return new String(result, 0, dst); }  }
CaseTools { public static String snake(String s) { if (s == null) { return null; } int dst = 0; final var result = new char[2 * s.length()]; for (int src = 0; src < s.length(); src++) { if (Character.isUpperCase(s.charAt(src)) && src > 0) { result[dst++] = '_'; } result[dst++] = Character.toUpperCase(s.charAt(src)); } return new String(result, 0, dst); }  static String lcase(String s); static String ucase(String s); static String camel(String s); static String snake(String s); }
CaseTools { public static String snake(String s) { if (s == null) { return null; } int dst = 0; final var result = new char[2 * s.length()]; for (int src = 0; src < s.length(); src++) { if (Character.isUpperCase(s.charAt(src)) && src > 0) { result[dst++] = '_'; } result[dst++] = Character.toUpperCase(s.charAt(src)); } return new String(result, 0, dst); }  static String lcase(String s); static String ucase(String s); static String camel(String s); static String snake(String s);  }