Lang 1463: StringUtils abbreviate returns String of length greater than maxWidth (#477)
* fixed LANG-1463 StringUtils abbreviate returns String of length greater than maxWidth * fixed LANG-1463 StringUtils abbreviate returns String of length greater than maxWidth * fixed LANG-1463 StringUtils abbreviate returns String of length greater than maxWidth * formatting fix * removed magic string
This commit is contained in:
parent
24e6468683
commit
d0b95be281
|
@ -294,7 +294,6 @@ public class StringUtils {
|
||||||
public static String abbreviate(final String str, final String abbrevMarker, final int maxWidth) {
|
public static String abbreviate(final String str, final String abbrevMarker, final int maxWidth) {
|
||||||
return abbreviate(str, abbrevMarker, 0, maxWidth);
|
return abbreviate(str, abbrevMarker, 0, maxWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Abbreviates a String using a given replacement marker. This will turn
|
* <p>Abbreviates a String using a given replacement marker. This will turn
|
||||||
* "Now is the time for all good men" into "...is the time for..." if "..." was defined
|
* "Now is the time for all good men" into "...is the time for..." if "..." was defined
|
||||||
|
@ -333,10 +332,13 @@ public class StringUtils {
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
public static String abbreviate(final String str, final String abbrevMarker, int offset, final int maxWidth) {
|
public static String abbreviate(final String str, final String abbrevMarker, int offset, final int maxWidth) {
|
||||||
if (isEmpty(str) || isEmpty(abbrevMarker)) {
|
if (isEmpty(str) && isEmpty(abbrevMarker)) {
|
||||||
|
return str;
|
||||||
|
} else if (isNotEmpty(str) && EMPTY.equals(abbrevMarker) && maxWidth > 0) {
|
||||||
|
return str.substring(0, maxWidth);
|
||||||
|
} else if (isEmpty(str) || isEmpty(abbrevMarker)) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int abbrevMarkerLength = abbrevMarker.length();
|
final int abbrevMarkerLength = abbrevMarker.length();
|
||||||
final int minAbbrevWidth = abbrevMarkerLength + 1;
|
final int minAbbrevWidth = abbrevMarkerLength + 1;
|
||||||
final int minAbbrevWidthOffset = abbrevMarkerLength + abbrevMarkerLength + 1;
|
final int minAbbrevWidthOffset = abbrevMarkerLength + abbrevMarkerLength + 1;
|
||||||
|
|
|
@ -236,6 +236,13 @@ public class StringUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
//Fixed LANG-1463
|
||||||
|
@Test
|
||||||
|
public void testAbbreviateMarkerWithEmptyString() {
|
||||||
|
String greaterThanMaxTest = "much too long text";
|
||||||
|
assertEquals("much too long", StringUtils.abbreviate(greaterThanMaxTest, "", 13));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbbreviate_StringInt() {
|
public void testAbbreviate_StringInt() {
|
||||||
assertNull(StringUtils.abbreviate(null, 10));
|
assertNull(StringUtils.abbreviate(null, 10));
|
||||||
|
|
Loading…
Reference in New Issue