mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-10-19 05:53:59 +00:00
Fixed #20. Added support for removeNonWords function
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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")));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user