mirror of
https://github.com/shekhargulati/strman-java.git
synced 2026-09-26 21:03:56 +00:00
Fixed #45. Added support for truncate function
This commit is contained in:
@@ -866,6 +866,25 @@ public abstract class Strman {
|
||||
return value.split("\\W+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the unsecured form string, cutting the independent string of required position.
|
||||
*
|
||||
* @param value Value will be truncated unsecurely.
|
||||
* @param length Size of the returned string.
|
||||
* @param filler Value that will be added to the end of the return string. Example: '...'
|
||||
* @return String truncated unsafely.
|
||||
*/
|
||||
public static String truncate(final String value, final int length, final String filler) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
if (length == 0) {
|
||||
return "";
|
||||
}
|
||||
if (length >= value.length()) {
|
||||
return value;
|
||||
}
|
||||
return append(value.substring(0, length - filler.length()), filler);
|
||||
}
|
||||
|
||||
public static String decode(final String value, final int digits, final int radix) {
|
||||
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
|
||||
return Arrays
|
||||
|
||||
Reference in New Issue
Block a user