This commit is contained in:
Shekhar Gulati
2016-08-24 15:32:45 +05:30
parent bacbe46529
commit 61ca9fc984
2 changed files with 47 additions and 1 deletions
+31 -1
View File
@@ -1236,7 +1236,7 @@ public abstract class Strman {
/**
* Removes leading whitespace from string.
* Removes leading characters from string.
*
* @param input The string to trim.
* @param chars The characters to trim.
@@ -1252,6 +1252,36 @@ public abstract class Strman {
});
}
/**
* Removes trailing whitespace from string.
*
* @param input The string to trim.
* @return Returns the trimmed string.
*/
public static Optional<String> trimEnd(final String input) {
return Optional.ofNullable(input)
.filter(v -> !v.isEmpty())
.map(Strman::rightTrim);
}
/**
* Removes trailing characters from string.
*
* @param input The string to trim.
* @param chars The characters to trim.
*
* @return Returns the trimmed string.
*/
public static Optional<String> trimEnd(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)) {