Fixed #40. Added support for toSnakeCase function

This commit is contained in:
Shekhar Gulati
2016-05-22 19:09:04 +05:30
parent f6811a9905
commit 27d10cb985
2 changed files with 29 additions and 0 deletions
+10
View File
@@ -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
+19
View File
@@ -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")));
}
}