Modified the behavior of truncate() that takes a third parameter:
the string is tested against maxLength, but is trimmed at a point such that the result string will be maxLength after the addition of the 'append' parameter. I'm pretty sure nothing (around these parts) depended on the old behavior. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1894 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -81,6 +81,8 @@ public class StringUtil
|
||||
|
||||
/**
|
||||
* Truncate the specified String if it is longer than maxLength.
|
||||
* The string will be truncated at a position such that it is
|
||||
* maxLength chars long after the addition of the 'append' String.
|
||||
*
|
||||
* @param append a String to add to the truncated String only after
|
||||
* truncation.
|
||||
@@ -90,7 +92,7 @@ public class StringUtil
|
||||
if ((s == null) || (s.length() <= maxLength)) {
|
||||
return s;
|
||||
} else {
|
||||
return s.substring(0, maxLength) + append;
|
||||
return s.substring(0, maxLength - append.length()) + append;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user