This commit is contained in:
Shekhar Gulati
2016-08-24 15:02:00 +05:30
parent 9b60adf732
commit bacbe46529
2 changed files with 47 additions and 0 deletions
+31
View File
@@ -1222,6 +1222,37 @@ public abstract class Strman {
.get();
}
/**
* Removes leading whitespace from string.
*
* @param input The string to trim.
* @return Returns the trimmed string.
*/
public static Optional<String> trimStart(final String input) {
return Optional.ofNullable(input)
.filter(v -> !v.isEmpty())
.map(Strman::leftTrim);
}
/**
* Removes leading whitespace from string.
*
* @param input The string to trim.
* @param chars The characters to trim.
*
* @return Returns the trimmed string.
*/
public static Optional<String> trimStart(final String input, String... chars) {
return Optional.ofNullable(input)
.filter(v -> !v.isEmpty())
.map(v -> {
String pattern = String.format("^[%s]+", join(chars, "\\"));
return v.replaceAll(pattern, "");
});
}
private static void validate(String value, Predicate<String> predicate, final Supplier<String> supplier) {
if (predicate.test(value)) {
throw new IllegalArgumentException(supplier.get());