mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-09-25 11:33:55 +00:00
Fixed #40. Added support for toSnakeCase function
This commit is contained in:
@@ -1033,6 +1033,16 @@ public abstract class Strman {
|
||||
return toDecamelize(value, "-");
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform to snake_case.
|
||||
*
|
||||
* @param value The input String
|
||||
* @return String in snake_case.
|
||||
*/
|
||||
public static String toSnakeCase(final String value) {
|
||||
return toDecamelize(value, "_");
|
||||
}
|
||||
|
||||
public static String decode(final String value, final int digits, final int radix) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Arrays
|
||||
|
||||
@@ -776,4 +776,23 @@ public class StrmanTest {
|
||||
|
||||
Arrays.stream(fixture).forEach(el -> assertThat(String.format("toKebabCase(%s) should be de-camelize", el), toKebabCase(el), equalTo("de-camelize")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toSnakeCase_shouldSnakeCaseAString() throws Exception {
|
||||
String[] fixture = {
|
||||
"deCamelize",
|
||||
"de-Camelize",
|
||||
"de camelize",
|
||||
"de camelize",
|
||||
"de Camelize",
|
||||
"de-camelize",
|
||||
"-de--camelize",
|
||||
"de_camelize",
|
||||
" de_camelize"
|
||||
};
|
||||
|
||||
Arrays.stream(fixture).forEach(el -> assertThat(String.format("toSnakeCase(%s) should be de_camelize", el), toSnakeCase(el), equalTo("de_camelize")));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user