Added truncate().

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4353 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-09-01 01:05:23 +00:00
parent 9e1f81ceff
commit 8f958e2505
+18
View File
@@ -50,5 +50,23 @@ public class StringUtil
{
return mx.utils.StringUtil.trim(str);
}
/**
* 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.
*/
public static function truncate (
s :String, maxLength :int, append :String = "") :String
{
if ((s == null) || (s.length <= maxLength)) {
return s;
} else {
return s.substring(0, maxLength - append.length) + append;
}
}
}
}