Fixed #38. Added support for toKebabCase function

This commit is contained in:
Shekhar Gulati
2016-05-22 19:05:56 +05:30
parent 4bff84d869
commit f6811a9905
2 changed files with 41 additions and 1 deletions
+10
View File
@@ -1023,6 +1023,16 @@ public abstract class Strman {
return Arrays.stream(words).map(w -> w.toLowerCase()).collect(joining(Optional.ofNullable(chr).orElse(" ")));
}
/**
* Transform to kebab-case.
*
* @param value The input String
* @return String in kebab-case.
*/
public static String toKebabCase(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
+31 -1
View File
@@ -743,7 +743,37 @@ public class StrmanTest {
@Test
public void toDeCamelCase_shouldDeCamelCaseAString() throws Exception {
assertThat(toDecamelize("camelCase", null), equalTo("camel case"));
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("toDecamelize(%s) should be de-camelize", el), toDecamelize(el, null), equalTo("de camelize")));
assertThat(toDecamelize("camelCase", "_"), equalTo("camel_case"));
}
@Test
public void toKebabCase_shouldKebabCaseAString() 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("toKebabCase(%s) should be de-camelize", el), toKebabCase(el), equalTo("de-camelize")));
}
}