Fixed #37. Added support for toDeCamelCase function

This commit is contained in:
Shekhar Gulati
2016-05-22 19:00:39 +05:30
parent 09793e71f5
commit 4bff84d869
2 changed files with 18 additions and 0 deletions
+12
View File
@@ -1011,6 +1011,18 @@ public abstract class Strman {
return last(value, value.length() - 1);
}
/**
* Decamelize String
*
* @param value The input String
* @return String decamelized.
*/
public static String toDecamelize(final String value, final String chr) {
String camelCasedString = toCamelCase(value);
String[] words = camelCasedString.split("(?=\\p{Upper})");
return Arrays.stream(words).map(w -> w.toLowerCase()).collect(joining(Optional.ofNullable(chr).orElse(" ")));
}
public static String decode(final String value, final int digits, final int radix) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return Arrays
+6
View File
@@ -740,4 +740,10 @@ public class StrmanTest {
assertThat(toCamelCase("c"), equalTo("c"));
}
@Test
public void toDeCamelCase_shouldDeCamelCaseAString() throws Exception {
assertThat(toDecamelize("camelCase", null), equalTo("camel case"));
assertThat(toDecamelize("camelCase", "_"), equalTo("camel_case"));
}
}