Added the second fix from Mark McDowell [mcdoma@ncs.com] for bug #14062

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137160 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2002-11-23 00:54:24 +00:00
parent de74831603
commit 28f37f2b4d
1 changed files with 8 additions and 9 deletions

View File

@ -73,7 +73,7 @@ import java.util.Iterator;
* @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
* @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
* @version $Id: StringUtils.java,v 1.25 2002/11/16 10:41:03 scolebourne Exp $
* @version $Id: StringUtils.java,v 1.26 2002/11/23 00:54:24 bayard Exp $
*/
public class StringUtils {
@ -487,22 +487,21 @@ public class StringUtils {
String[] list = new String[listSize];
int i = 0;
int lastTokenBegin = 0;
int lastTokenEnd = 0;
while (tok.hasMoreTokens()) {
if (max > 0 && i == listSize - 1) {
// In the situation where we hit the max yet have
// tokens left over in our input, the last list
// element gets all remaining text.
StringBuffer buf = new StringBuffer((int) 1.2 * str.length() * (listSize - i) / listSize);
while (tok.hasMoreTokens()) {
buf.append(tok.nextToken());
if (tok.hasMoreTokens()) {
buf.append(separator);
}
}
list[i] = buf.toString();
String endToken = tok.nextToken();
lastTokenBegin = str.indexOf(endToken, lastTokenEnd);
list[i] = str.substring(lastTokenBegin);
break;
} else {
list[i] = tok.nextToken();
lastTokenBegin = str.indexOf(list[i], lastTokenEnd);
lastTokenEnd = lastTokenBegin + list[i].length();
}
i++;
}