Fixed #20. Added support for removeNonWords function

This commit is contained in:
Shekhar Gulati
2016-05-21 19:06:07 +05:30
parent 2812d51da4
commit ba7020d594
2 changed files with 23 additions and 0 deletions
+11
View File
@@ -697,6 +697,17 @@ public abstract class Strman {
return fx.apply(value.toLowerCase(), prefix.toLowerCase());
}
/**
* Remove all non word characters.
*
* @param value The input String
* @return String without non-word characters
*/
public static String removeNonWords(final String value) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return value.replaceAll("[^\\w]+", "");
}
public static String decode(final String value, final int digits, final int radix) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return Arrays
+12
View File
@@ -524,4 +524,16 @@ public class StrmanTest {
Arrays.stream(fixture).forEach(el -> assertThat(removeLeft(el, "FOO", false), equalTo("bar")));
}
@Test
public void removeNonWords_shouldRemoveAllNonWordsFromInputString() throws Exception {
final String[] fixture = {
"foo bar",
"foo&bar-",
"foobar"
};
Arrays.stream(fixture).forEach(el -> assertThat(removeNonWords(el), equalTo("foobar")));
}
}