From 7cdbbd5fd791685b4e51df8d186aec680730c46e Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 1 Sep 2006 01:00:12 +0000 Subject: [PATCH] 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 --- src/java/com/samskivert/util/StringUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/java/com/samskivert/util/StringUtil.java b/src/java/com/samskivert/util/StringUtil.java index d4ba265d..cb9556ce 100644 --- a/src/java/com/samskivert/util/StringUtil.java +++ b/src/java/com/samskivert/util/StringUtil.java @@ -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; } }